# HTML Templates Instead of Reactivity
8 December 2023
In this post, I will try to convince you that the amount of complexity you bring into your project to synchronize your application state with what a user sees on a screen is not worth it. **Reactivity** is not worth it. It's not worth it to use weird abstractions like **JSX** or other languages which produces **HTML** or **JS**. Bringing in build systems, package managers with tons of dependencies and other type of complexity like **Virtual DOM** just to build the frontend of your application is also not worth it.
## What's the Selling Point of Modern Frameworks? Let's take a look at what **React** uses as an example: ```jsx function MyButton() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return ( ); } ``` The idea here is that you don't need to directly update the value of the button when the value of `count` is being changed. I understand that real examples are way more complex, and while this specific example may not appear particularly impressive, it serves as a demonstration of the framework's functionality. I also understand that the same example in other frameworks like Svelte looks less weird. My point is here that we still can reduce the amount of complexity.
## Let's First Try VanillaJS (Attempt #1) I think the example above can be rewritten in plain JS much easier: ```html ``` While I write these words, I can already hear the voices of people complaining about how this is insufficient, how it's silly to update the DOM directly, and how it's insane to keep the application state right within the attributes of elements. It's funny because I don't really have an application state here; all I have is the DOM that contains useful information which I can extract and use. And yes, for large projects, the solution above may not be the best approach because large applications actually must have some state. So, let's talk about **application state...**
## Application State Must Be Global The idea is that we must attach certain objects to specific elements or components cause us a lot of troubles. For some reason, we decided that global objects are evil. However, I don't see any real objective reason to think like that. Sure, there may be name collisions, but those issues are easily detectable and avoidable simply by naming things in a more concrete and distinctive way. For some reason, it's okay to have DOM which is global within `window`. It's okay to have global structures like `sessionStorage` and `localStorage` and many other things within `window`. But it's not okay to separate global state of your application. To me it's seems inconsistent and quite harmful.
## Still VanillaJS (Attempt #2) Let's use now global state: ```html ``` As you can see, it's a bit better because we don't need the `data-count` attribute. In this case, we do use the application state, and yes, it's global. But what if we have many more elements that must visualize data? What if we cannot attach event handlers in such a way where we can easily access our elements? I hear you, and I have a solution: `