Skip to content

Instantly share code, notes, and snippets.

@sqndr
Created April 30, 2020 07:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Replace every instance with react component
import { render } from 'react-dom';
const renderComponent = (Component, root) => {
const parent = document.createElement('div');
render(Component, parent, () => {
root.replaceWith(...Array.from(parent.childNodes));
});
};
const renderMultiple = (Component, root) => {
const containers = document.querySelectorAll(root);
if (containers.length) {
Array.from(containers).map(container => renderComponent(
Component,
container,
));
}
};
export { renderComponent, renderMultiple };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment