News for hackers. Stuff that matters.
Re:Building a Front End Framework; Reactivity, Composability... by es7 on Sunday May 14, 2023 @02:59PM (#35940410)
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.

Re:Building a Front End Framework; Reactivity, Composability... by wbobeirne on Sunday May 14, 2023 @03:03PM (#35940438)
This 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!