Created
January 29, 2020 00:31
-
-
Save omichelsen/dd9dd28f81b19b121fe78a45b3057a76 to your computer and use it in GitHub Desktop.
Creates a function that will render a React component into a target element and return an unmount function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render, unmountComponentAtNode } from 'react-dom' | |
/** | |
* Creates a function that will render a React component into a target element and return an unmount function. | |
* The entry point should be loaded async by a ReactLoader component to ensure code splitting. | |
* @param component Root component to render | |
*/ | |
export default <P>(component: React.ComponentType<P>) => (domElement: Element, props: P) => { | |
render(React.createElement(component, props), domElement) | |
return () => { | |
unmountComponentAtNode(domElement) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment