Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 1.34 KB

File metadata and controls

37 lines (25 loc) · 1.34 KB

React State example

Running the application

yarn install && yarn start

Open State example subpage.

State in React

React documentation on state.

The main way to pass data between React components is to use props which are immutable. In order to have data that changes, state must be used.

Mutable state and how applications react to mutations is generally hard to understand. Therefore React limits the usage of state to a single Component. No other Components can read or change the state of other Components.

State can be initialized in the class constructor or using the useState hook

Components in the example

Build on top of the props example.

  • App has local state now - a list of comments that grows every 3 seconds.
  • CommentList has been upgraded to take a list of comment objects as props.