Interview Q&A / React

INTERVIEW Q&A · 58 QUESTIONS

React interview questions

Rendering, state, hooks, keys and effects, explained with small examples.

  1. 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
  2. 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