All jobs / Frontend / web developer / React
Frontend / web developer interview question · 0–1 years
What is the difference between props and state?
The strongest answer
Props are inputs passed from a parent and read-only in the child; state is data a component owns and changes over time, and changing it re-renders the component
Why it works
Right. Owned and mutable versus given and read-only.
What a good answer covers
- Props: passed in, read-only.
- State: owned, changed with a setter.
- Setting state re-renders.
- Lift state up when siblings share it.
Answers that fall short
- Close, but not the strongest: Props are for text, state is for numbers
Type has nothing to do with it. - Weak: State comes from the parent, props are internal
Backwards. - Red flag: They are the same thing
Different ownership, different rules.
Who gets asked this
More React questions
- What does useState return, and why must you call the setter instead of assigning?
- Why does React warn about a missing key when you render a list?
- What is a controlled input?
- What is useEffect for?
- What happens if useEffect has an empty dependency array, and if it has none at all?
- How do you render something only when a condition holds?
- Why does onClick={handleClick()} fire during render instead of on click?
- Two sibling components need the same piece of data. Where does it live?