Skip to content
ReactPy
Use State
Initializing search
ReactPy
Home
Get Started
Learn
Reference
About
ReactPy
ReactPy
Home
Get Started
Get Started
Overview
Overview
Quick Start
Tutorial: Tic-Tac-Toe
Thinking in React
Installation
Installation
Creating a Standalone React App
Add React to an Existing Project
Setup
Setup
Editor Setup
Tools, Libraries, and Packages
Learn
Learn
Describing the UI
Describing the UI
Your First Component
Importing and Exporting Components
Passing Props to a Component
Conditional Rendering
Rendering Lists
Keeping Components Pure
Adding Interactivity
Adding Interactivity
Responding to Events
State: A Component's Memory
Render and Commit
State as a Snapshot
Queueing a Series of State Updates
Updating Objects in State
Updating Arrays in State
Managing State
Managing State
Reacting to Input with State
Choosing the State Structure
Sharing State Between Components
Preserving and Resetting State
Extracting State Logic into a Reducer
Passing Data Deeply with Context
Scaling Up with Reducer and Context
Escape Hatches
Escape Hatches
Referencing Values with Refs
Manipulating the DOM with Refs
Synchronizing with Effects
You Might Not Need an Effect
Lifecycle of Reactive Effects
Separating Events from Effects
Removing Effect Dependencies
Reusing Logic with Custom Hooks
Communicating Data Between Server and Client
Convert Between VDOM and HTML
VDOM Mutations
Creating VDOM Event Handlers
Creating HTML Tags
Creating Backends
Manually Register a Client
Reference
Reference
Overview
Hooks
Hooks
Use State
Use State
Table of contents
Overview
Reference
use_state(initial_value)
Parameters
Returns
Caveats
set_value(next_value)
Parameters
Returns
Caveats
Usage
Adding state to a component
Counter (number)
Text field (string)
Checkbox (boolean)
Form (two variables)
Updating state based on the previous state
Is using an updater always preferred?
Passing the updater function
Passing the next state directly
Updating objects and arrays in state
Avoiding recreating the initial state
Passing the initializer function
Passing the initial state directly
Resetting state with a key
Storing information from previous renders
Use Effect
Use Async Effect
Use Context
Use Reducer
Use Callback
Use Memo
Use Ref
Use Debug Value
Use Connection
Use Scope
Use Location
HTML Tags
HTML Tags
Common Props
Usage