5 ms·
On a recent project, I’ve just been using JS template strings and .innerHTML all over the place. I don’t necessarily recommend it, but it’s been a good reminde
by es7 3y ago
On a recent project, I’ve just been using JS template strings and .innerHTML all over the place.
I don’t necessarily recommend it, but it’s been a good reminder to me that most of the value React provides me is literally just html-in-JS. In many cases the complexity that comes from React effects and state is unnecessary, and directly mutating DOM nodes is sometimes a lot less painful. Sometimes.
- wbobeirne 3y agoThis definitely works until you hit one of a few cases I can think of: * Adding animations to elements. By blowing away the DOM and inserting new elements each time, you'll trigger any css `animation` for new elements entering. * Stale data. If your template isn't re-run when some data changes for whatever reason, you'll continue to render the old data. You've got to manage the lifecycle of state updates yourself. * To counter that, you might just re-run your templates when _anything_ changes. This works until you have a significant amount of data, then performance starts to become an issue. This won't come up for many cases though, so for simpler apps it's definitely more than enough!