Props and State

Also called Properties, useState

Mentioned in
React Compiler
Updated

What is Props and State in React Native?

Props are the read-only inputs a component receives from its parent. State is the data a component owns and can change, triggering a re-render.

Parent"Ada"name—count (state)Counter A"Ada"props.namecount 0stateChild B"Ada"props.name—state
Prop on its way downComponentWrite to a prop: refusedProps come down from the parent and are read-only: a child never writes to them, and a new prop re-renders the child. State is owned by the component that calls useState, and its setter re-renders that component. When two components need the same value, lift the state to their closest common parent and pass it down to both as a prop; the child then asks the parent to change it, through a callback. A value that changes without needing a re-render belongs in a ref.

Props and state are the two ways data reaches a React Native component, and the difference decides where a value should live.

Props are arguments passed down from a parent. They are read-only: a component must never write to its own props. Changing a prop is the parent's job, and doing so re-renders the child.

State is data a component owns, created with the useState hook. Calling the setter schedules a re-render with the new value:

const [count, setCount] = useState(0);
<Button title={`Tapped ${count}`} onPress={() => setCount(count + 1)} />;

The practical rule newcomers ask about: if two components need the same value, lift the state up to their closest common parent and pass it down as props. If a value changes but should not trigger a re-render — a timer id, a scroll offset — it belongs in a ref instead.