tmpl-cli
api
docs
env
git
hbs
html
husky
jest
lintstaged
lisp
node
prettier
python
react
readme
schema
style
util
Summaryutil asyncutil cookieutil dynamicutil event-listenerutil historyutil polyfillsutil react
vue
web

$ tmpl util react

Adds react util.

Files

project
└─src
└──utils
└───react.jsx

react.jsx

import React from "react";
import { hydrate, render } from "react-dom";
export const initReact = (rootId, method, jsx) => {
const rootElement = document.getElementById(rootId);
if (rootElement) {
if (method === "render") {
render(jsx, rootElement);
} else {
hydrate(jsx, rootElement);
}
} else {
console.error(`Could not find element with ID: ${rootId}`);
}
};
// window.addEventListener("DOMContentLoaded", () => initReact("root", "render", <div>React Working</div>));