State contains data about the component. When the state changes, the component will rerender and that's what makes React so powerful

 

Each component in React has its own state, which it manages and generates its own life cycle. This life cycle is used to re-render HTML in response to state changes.

As a single page application is that the Dom is always rerendering itself based on the state of a specific component.

 

There are two methods for managing state: 

  • Managed by useState is the local state. 
  • State management libraries like as Redux or MobX, or the Context API, are used to manage the global state.

 

// Local state :
const [count, setCount] = useState(0);

// Context API - global state:
const AppContext = React.createContext();


Related Question