CodeSweetly

CodeSweetly

React State Explained Clearly

A Beginner’s Guide to the useState Hook

Mar 17, 2026
∙ Paid
Learn the useState Hook from Scratch

React state is a component’s memory for storing data. This component-specific memory has two primary attributes that differentiate it from a regular JavaScript variable:

  1. It persists (retains its data) during the component’s re-rendering.

  2. Modifying it causes React to re-render the component with the updated state.

Tip:

  • React rendering means invoking (calling) a component.

  • React State retains data during a component’s re-rendering, not when a page reloads. Refreshing your browser will cause React to re-initialize the entire application. Therefore, all states will revert to their initial values.

  • To retain your component’s state during reloads or when users reopen the web page or close their browsers, store the state data outside the app’s scope. Common persistent memory locations are web storage, cookies, and databases.

How to Access and Modify a Function Component’s State

React provides the useState() method (the state hook) for accessing and modifying a function component’s state.

Example:

import { useState } from "react";

function MyBio() {
  const myName = useState("Oluwatobi");
  return <h1>My name is {myName[0]}</h1>;
}

export default MyBio;

Try it on CodeSandbox

The snippet above used React’s useState() function to store the "Oluwatobi" string inside the MyBio component’s state memory.

User's avatar

Continue reading this post for free, courtesy of CodeSweetly.

Or purchase a paid subscription.
© 2026 CodeSweetly · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture