React is a wrapper built on top of HTML, CSS, JS combined.

There are mainly three concepts to be understood:

  1. States : The dynamic objects that will be changed in the frontend.
  2. Components : Classes that contain and control UI elements, these also may contain the states.
  3. React-DOM : The package responsible to connect react to the HTML DOM that does the rendering at the backend.

In layman terms, states are the elements that are to be changed, components is a bag of these elements once you have the bag in your workplace you have all the states and the other dependent UI components and React-DOM is the person that understands what there states and components are and brings them to life.

Let’s dive into it and understand. This is a simple counter App

import { useState } from 'react'
import './App.css'

function App() {
  return (
    <div>
      <Counter />
    </div>
    
  )
}

function Counter() {
  const [count, setCount] = useState(0);

  function countIncreaser() {
    setCount(count + 1);
  }
  return(
    <>
      <div>The count is {count}</div>
      <button onClick={countIncreaser}>Increase</button>
    </>
  )
}

export default App;

Here, there are a couple of things going on. Let’s break them down.

There’s a problem in this app though, every time button is pressed the count variable is re-rendered but the button renders again, this happens and you can use react-dev-tools to see this on chrome. I’ll discuss how to solve this in the next sections.