Not every page needs React. For small sites, vanilla JavaScript is fast and has no build step. The trick is keeping it organized.
A few habits help:
- Wrap page scripts in an IIFE so nothing leaks into the global scope.
- Use
addEventListenerwith event delegation instead of inline handlers. - Check that an element exists before you attach a listener to it.
- Keep DOM selectors in one place near the top of the file.
These rules are simple, but they make a script easy to read six months later.