What is the useState hook?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex React.js topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
useState is a React hook that adds state to a function component. const [state, setState] = useState(initialValue); returns a pair: the current state value and a function to update it. The initial value is used only on the first render. Updating state: setState(newValue) — React schedules a re-render with the new state. Functional updates: when the new state depends on the old state, use setState(prev => prev + 1) — this guarantees you get the latest value even if updates are batched. Object/array state: you must create new objects/arrays instead of mutating — setUser({ ...user, name: "Alice" }), not user.name = "Alice". Lazy initialization: pass a function to useState to compute the initial value only once (useful for expensive calculations): useState(() => computeExpensiveValue()). Multiple useState calls are independent. State is preserved across re-renders and reset only when the component unmounts or its key changes.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.