Interview Q&A / React
React interview questions
Rendering, state, hooks, keys and effects, explained with small examples.
Prefer rapid revision? Practise React short interview answers →
- How do you render a list in React and handle the empty case?
Use array.map inside JSX to turn data into elements with keys. Check the array length first and show an empty-state message when there is nothing to display, instead of rendering a blank area.
BeginnerQuick answer1 min read - Why does {count && <Badge />} show 0 on the screen when count is zero?
The && operator returns the left side when it is falsy, and React renders the number 0. Convert to a boolean first: {count > 0 && <Badge />}, or use a ternary.
BeginnerQuick answer1 min read