DEV Community

Discussion on: Why to use React if HTML/CSS/JS works fine?

Collapse
jjhiggz profile image
Jonathan Higger

Sometimes it feels like event-driven changes get messy very fast and become hard to manage.

For example lets say you do a simple to do list app.

In JS it goes like this

User clicks form -> event listener is fired -> finds a dom element on the page -> adds the todo

Then if you want to maybe filter todos
User clicks add button -> event fired -> finds all the todos inside a dom element -> filters those elements down -> replaces all todos inside a dom element

In react its more like this

you have a state of todos that is an array of objects . For example one todo might look like { task: "go to the store" }. When that array changes the children component change too, or react to the change in state (hence the name).

User clicks add button -> event fired -> set the state of todos

User clicks filter button -> event fired -> set the state of todos

That's all the logic you need. In this small example its not a big time saver, but in other circumstances it can save a lot of effort once you get good at it.

ALSO you can basically incorporate HTML and Javascript seamlessly using React's Templating language(JSX is what it's called).

You can still make just as good of projects in either way though, it just might be easier in react, especially if there is a lot going on. There is also plenty of alternatives to React. The smart people I know love a library called Ember, but I've never used it and apparently it's kind of hard to learn. Also there's Vue and Angular