10 ms·
We need a little more than that, though. You can accomplish that right now with JS template string literals and innerHTML: function myComponent(props) {
by _bxg1 7y ago
We need a little more than that, though. You can accomplish that right now with JS template string literals and innerHTML:
function myComponent(props) {
return `
<div>
${props.name}
</div>
`
}
...
document.body.innerHTML = myComponent({ name: "Bob" });
The problem is that it always completely obliterates the DOM, instead of changing just the parts that need to change. The browser, of course, has plenty of information with which to do that in C++ instead of requiring the use of something like React. But for some reason it hasn't been implemented.
- dnautics 7y agoYou may be looking for morphdom, which is a very lightweight version of what you want, but of course browser support for this would be nice. https://github.com/patrick-steele-idem/morphdom https://github.com/patrick-steele-idem/morphdom
- numtel 7y agoLithtml implements declarative DOM using string literals like this very efficiently. I'm of the opinion that sticking with React when Lithtml exists is just fear of writing vanilla classes.