DEV Community

LawranceMichaelite
LawranceMichaelite

Posted on

Why should I need React ?

I am just starting out to learn Web-development. Since from the beginning I am hearing this buzz-word React.
So I would like to know

  • Why should one use React for front-end dev ?
  • Why should one consider front-end libraries and framework for building UI instead of Plain JS/CSS ?

P.S :- I have already try searching about it. I couldnt understand some technical terms. So please answer in plain English as possible.

Thank You

Top comments (3)

Collapse
 
dz4k profile image
Deniz Akşimşek • Edited

Here's how I understand it. It might be inaccurate or incomplete because I don't really use frontend frameworks, this is based on what I've read and seen from others.

Why should one use React for front-end dev ?

When you write vanilla JS code for a UI component, you have to write:

  • Code to create the HTML elements (this part might be server side code instead of JS)
  • Code to modify the elements when something changes

These two are often similar and when you change one, you often need to change the other too.

React and other virtual-DOM based frameworks allow you to write code to create "v-nodes" which are objects that represent HTML elements, but are faster to create because they don't render anything. React deals with modifying the UI by re-running the creation code and comparing the old vnodes with the new, and applying the changes to the actual document.

One disadvantage of React and other JS frameworks is that for it to work, all the elements need to be created via JS, which means it won't work until your code finishes running. The code may be slow, or JS might be unavailable (network timeout, some people turn it off, many search engines do not run JS). There is a solution which is SSR (server-side rendering) that uses Node.js to run your code and generate HTML from that. The user will see a frozen page until the JS code finishes loading in the browser (might not be a significant issue if your code is small and fast).

Why should one consider front-end libraries and framework for building UI instead of Plain JS/CSS ?

I recommend trying plain JS first, and adopting a frontend framework when your code is getting messy and you can't decide how to clean it up.

Collapse
 
hxii profile image
Paul (hxii) Glushak

Do yourself a favor and learn vanilla JS as well as mastering HTML and CSS before going into ANY frameworks.
People nowadays are quick to jump onto the "next best thing" (literally ANY CSS/JS framework, according to them) while knowing next to nothing about the basics.

Collapse
 
lawrancemichaelite profile image
LawranceMichaelite

Sure I'll do it. Thanks a lot 🎉