Nearby lessons

7 of 43

πŸ“¦ ReactJS – State

πŸ“Œ What is State?

πŸ“Œ What is State in React?

State is a built-in object that allows components to **store and manage data** that can change over time.

πŸ“Œ Key Points About State

  • State is **mutable**, meaning it can be changed by the component.
  • State allows React components to remember data between renders.
  • State is managed **inside the component**.
  • State changes trigger **re-rendering** of the component.
  • In functional components, state is used with the useState hook.

βš™οΈ Using useState Hook

The useState hook is used to declare state variables in functional components.
Example03
Loading editor…

πŸ”„ Updating State

You can update state using the setter function returned by useState.

Every time state changes, React re-renders the component automatically.

Example04
Loading editor…

πŸ‘Ά Using State with Multiple Components

State can be used in multiple components independently.

Each component manages its own state using useState hook.

Example05
Loading editor…

πŸ”— Props vs State

Props and State are both used to store data in React, but they have key differences:

  • Props: Passed from parent to child, immutable, used for communication.
  • State: Managed inside the component, mutable, used for data that can change over time.

🧠 Test Your Knowledge

4 Questions
Progress: 0 / 4