All jobs / Frontend / web developer / React
Frontend / web developer interview question · 0–1 years
What is a controlled input?
The strongest answer
An input whose value comes from state and whose onChange updates that state, so React is the single source of truth for what the field shows
Why it works
Right. Value from state, change into state.
What a good answer covers
- value={state} onChange={set}.
- React owns the field's value.
- Uncontrolled: the DOM owns it, read via ref.
- Do not switch between the two.
Answers that fall short
- Close, but not the strongest: An input with validation
Validation can be added but is not the definition. - Weak: An input the user cannot edit
It is fully editable; React just owns the value. - Red flag: An input inside a form tag
The form tag is irrelevant.
Who gets asked this
More React questions
- 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?
- Why does a component return a fragment instead of a wrapping div?
- Why does items.push(x); setItems(items) not re-render?
- When is a React piece a reusable component versus a page-level screen?