Skip to main content

Command Palette

Search for a command to run...

Understanding State in React: The Backbone of Dynamic UIs

Updated
2 min read
Understanding State in React: The Backbone of Dynamic UIs
R

Frontend developer who weaves creativity and code, book lover, avid traveller and a tech enthusiast

When you build applications with React, state is one of the most essential concepts to master. It’s what gives React components their dynamic and interactive behavior. Without state, your React app is just static HTML with JavaScript syntax.

If we have to elaborate more then state lets your app remember things like user input, button clicks, or whether something is visible or hidden — and when the state changes, the UI updates automatically.

In a nutshell, state is a way to store and manage changing information in a component.

State is a JavaScript object that stores dynamic data in a component.

How to use state in functional component

import React, { useState } from 'react';

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

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>Increase</button>
    </div>
  );
}

Below is the breakdown of above code:

  • useState is the hook that lets you add state to the component.

  • count holds the initial / current value.

  • setCount is the setter function which is used to set or update the value.

For more clarity you can refer this structure

const [stateValue, setStateValue] = useState(initialValue);

👍 Updating state

Correct way ✅

setCount((prevCount) => prevCount + 1)

This ensures you’re using the most recent value of the state. Also remember, when your new state depends on the previous state, you have to update the value in above way.

Wrong way ❌

setCount(count + 1)

This works but can lead to bugs 🐞 in cases where state updates depend on previous state values.

🖥️ Best practices for managing state

  • Keep state minimal: Only store what’s necessary.

  • Use local state first: Don’t jump to global state too early.

  • Don’t mutate state directly: Always use setState or useState updater.

  • Separate concerns: Keep UI logic and state logic manageable and modular.

😶‍🌫️ Conclusion

State is what gives life to your React components. Whether you're toggling a button, fetching an API, or building a dynamic dashboard — state is at the core of it.

Mastering state management means:

  • More predictable UIs

  • Better performance

  • Easier scalability

So the next time someone says "React is just JavaScript", you’ll know — the real power lies in managing state effectively.

React

Part 5 of 5

My goal is to make complex concepts easier to grasp, especially for beginners who are just getting started with React. No jargon, no fluff — just clear, beginner-friendly content to help you build confidence in React step by step.

Start from the beginning

Understanding Controlled and Uncontrolled Components in React

Handling form is an integral part in React as most web apps rely a lot on the user input. React provides two approaches of handling form. They are via: Controlled component Uncontrolled component Each method has their own pros and cons. Lets disc...

More from this blog

Raj's Blog

25 posts

I am a passionate Frontend Developer who loves to make internet beautiful and useful. I love to share what I have learnt and love to learn new techs. A bibliophile, tech enthusiast and a cynophilist.