Optimize render in src/js/main/main.tsx

This commit is contained in:
0x1eef 2024-04-25 03:53:28 -03:00
parent 37e163aabd
commit c36d7c5e12

View file

@ -7,33 +7,34 @@ import { Task } from "~/components/Task";
(function () { (function () {
const components = { const components = {
"react-newtask": ( "react-newtask": () => (
<App> <App>
<Task /> <Task />
</App> </App>
), ),
"react-edittask": ( "react-edittask": () => (
<App> <App>
<Task /> <Task />
</App> </App>
), ),
"react-tasks": ( "react-tasks": () => (
<App> <App>
<Tasks /> <Tasks />
</App> </App>
), ),
"react-projects": ( "react-projects": () => (
<App> <App>
<Projects /> <Projects />
</App> </App>
) )
}; };
Object const ents = Object.entries(components);
.entries(components) for (let i = 0; i < ents.length; i++) {
.forEach(([name, jsx]) => { const [name, getJSX] = ents[i];
const root = document.querySelector(`.${name}`); const root = document.querySelector(`.${name}`);
if (root) { if (root) {
ReactDOM.createRoot(root).render(jsx); ReactDOM.createRoot(root).render(getJSX());
break;
}
} }
});
})(); })();