Conditional rendering React Questions

Master conditional rendering react interviews with our comprehensive collection of 8 questions and challenges.

Type:
Sort:
Difficulty:

Apply conditional CSS in React using className with ternary, the cn() utility, and inline styles. Know which approach to use and when.

beginnerreactconditional stylesclassName

Render elements conditionally in React using if/else, ternary operators, logical AND, and null returns. Know the gotchas for each approach.

beginnerreactconditional renderingternary

Conditional rendering in React is JavaScript control flow applied to JSX. Learn the four patterns, when to use each, and the gotchas that catch candidates off guard.

beginnerreactconditional renderingjsx

Use dangerouslySetInnerHTML to render HTML strings from a CMS or API, and always sanitize external content with DOMPurify to prevent XSS.

beginnerreactdangerouslySetInnerHTMLXSS

The key prop lets React match list elements across renders for efficient diffing. Using index as key is a common bug. Understand why and how to fix it.

beginnerreactkey proplist rendering

Use map() to transform arrays into JSX elements. Know when to use filter() and flatMap(), and how to handle nested arrays and empty states.

beginnerreactmaplist rendering

Toggle element visibility in React by combining useState with conditional rendering or CSS. Know when to unmount vs keep mounted.

beginnerreactconditional renderinguseState

Objects cannot be mapped directly in JSX. Use Object.entries(), Object.keys(), or Object.values() to convert to arrays first, then map to JSX.

intermediatereactobjectObject.entries