State Basics with useState

Harry · 22 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

The useState Hook

const [count, setCount] = useState(0);
setCount(c => c + 1);

Updating Objects and Arrays

Never mutate - spread into new values so React detects the change.

setUser(p => ({ ...p, email: next }));
setItems(p => [...p, item]);

State vs Props

State is local and mutable via its setter; props come from the parent and are read-only.

Key Points

  • State updates are async and may batch.
  • Use functional updates when state depends on previous state.
  • Lift shared state to the common parent.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in