Skip to content

Commit 1a24c24

Browse files
Add new ReactDom methods
1 parent f0b215c commit 1a24c24

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Fable.React/Fable.Import.React.fs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,17 +1138,30 @@ module React =
11381138
// member __.cloneElement(element: ReactElement, props: 'P, [<ParamArray>] children: ReactNode[]): ReactElement = jsNative
11391139
// member __.isValidElement(``object``: obj): bool = jsNative
11401140

1141+
open React
11411142

11421143
[<Erase>]
1143-
module ReactDom =
1144-
open React
1144+
type ReactDom =
1145+
/// Render a React element into the DOM in the supplied container.
1146+
/// If the React element was previously rendered into container, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React element.
1147+
/// If the optional callback is provided, it will be executed after the component is rendered or updated.
11451148
[<Import("render", "react-dom")>]
1146-
let render(element: ReactElement, container: Element): unit = jsNative
1149+
static member render(element: ReactElement, container: Element, ?callback: unit->unit): unit = jsNative
1150+
1151+
/// Same as render(), but is used to hydrate a container whose HTML contents were rendered by ReactDOMServer. React will attempt to attach event listeners to the existing markup.
1152+
[<Import("hydrate", "react-dom")>]
1153+
static member hydrate(element: ReactElement, container: Element, ?callback: unit->unit): unit = jsNative
1154+
1155+
/// Remove a mounted React component from the DOM and clean up its event handlers and state. If no component was mounted in the container, calling this function does nothing. Returns true if a component was unmounted and false if there was no component to unmount.
1156+
[<Import("unmountComponentAtNode", "react-dom")>]
1157+
static member unmountComponentAtNode(container: Element): bool = jsNative
1158+
1159+
/// Creates a portal. Portals provide a way to render children into a DOM node that exists outside the hierarchy of the DOM component.
1160+
[<Import("createPortal", "react-dom")>]
1161+
static member createPortal(child: ReactElement, container: Element): ReactElement = jsNative
11471162

11481163
[<Import("default", "react-dom/server")>]
11491164
module ReactDomServer =
1150-
open React
1151-
11521165
/// Render a React element to its initial HTML. This should only be used on the server. React will return an HTML string. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.
11531166
/// If you call ReactDOM.render() on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.
11541167
let renderToString(element: ReactElement): string = jsNative

0 commit comments

Comments
 (0)