React Junior interview questions and answers
75 questions for a React (Junior) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.What is React?
- 2.What is the virtual DOM in React?
- 3.What does JSX turn into at build time?
- 4.How do you set a CSS class on an element in JSX?
- 5.Why can't you write
{if (isAdmin) { <Admin /> }}inside JSX? - 6.Why doesn't the component
function card() { ... }work as<card />? - 7.How do you return two sibling elements from a component without an extra DOM wrapper?
- 8.Can you modify props inside a child component?
- 9.How can a child component pass data to its parent?
- 10.What is
childrenin React? - 11.What does
useState(0)return? - 12.What does
console.logprint after a click? - 13.What will
countbe after one click if the initial value is 0? - 14.Why didn't the component re-render?
- 15.What's the right way to add an item to an array in state?
- 16.Which value is best for
keyin a list? - 17.What is rendered if
items = []? - 18.What's wrong with
<button onClick={handleClick()}>? - 19.How do you cancel the default form submission behavior in React?
- 20.What is a controlled input?
- 21.React warns: "You provided a
valueprop to a form field without anonChangehandler". What happened? - 22.Two sibling components need the same data, which they can change. What should you do first?
- 23.What is prop drilling?
- 24.When does the effect
useEffect(() => { ... }, [])run? - 25.When does an effect without a dependency array run:
useEffect(() => { ... })? - 26.When is the function returned from
useEffectcalled? - 27.How does
useRefdiffer fromuseState? - 28.Which rule of hooks is broken?
- 29.Why must a custom hook's name start with
use? - 30.When does a child component re-render by default?
- 31.How do you set an inline style in JSX?
- 32.What steps are needed to pass data via Context?
- 33.What does
useContext(MyContext)return if there's no provider above the component? - 34.Why does
<StrictMode>call render and effects twice in development? - 35.What is
React.lazyused for? - 36.What does
React.lazyneed in order to work? - 37.Why does
lazy(() => import('./Chart'))fail ifChart.tsxhas onlyexport function Chart? - 38.What's dangerous about
dangerouslySetInnerHTML? - 39.How do you attach an app to a DOM element in React 18+?
- 40.What is a "pure" component in React terms?
- 41.How do you render a list of users from the
usersarray? - 42.What is Redux?
- 43.What's required of a reducer in classic Redux (without Immer)?
- 44.What does
configureStorefrom Redux Toolkit do? - 45.What are
useSelectoranduseDispatchfor? - 46.What does
createSlicegenerate? - 47.What problem does TanStack Query primarily solve?
- 48.What must you pass to
useQuery? - 49.How do
isPendingandisFetchingdiffer in TanStack Query v5? - 50.What must you do before using
useQueryin an app? - 51.How do you give a prop a default value in a function component?
- 52.How do you render one of two elements depending on a condition?
- 53.What should a component return to render nothing?
- 54.Which attribute links a
<label>to an input in JSX? - 55.Why does
<img src={url}>without a closing slash fail in JSX? - 56.How do you write a comment inside JSX markup?
- 57.When does
onChangefire on a text input in React? - 58.How do you pass an argument to a click handler?
- 59.How do you stop a click inside a card from also triggering the card's
onClick? - 60.Must
keyvalues be unique across the whole app? - 61.How do you add a
keywhen each list item renders several elements without a wrapper? - 62.How do you focus an input when a button is clicked?
- 63.What does
<Button {...props} />do? - 64.What do
{false},{null},{undefined}and{0}render in JSX? - 65.What is the naming convention for props that accept event handlers?
- 66.How does React recommend reusing UI between components?
- 67.How does
defaultValuediffer fromvalueon an input? - 68.How do you set the selected option of a
<select>in React? - 69.Why does this list render nothing?
- 70.What is React Developer Tools useful for?
- 71.What does the React team recommend for starting a new app today?
- 72.Two
<Counter />components are rendered on the page. Do they share state? - 73.Why doesn't clicking
<MyButton onClick={save} />callsave? - 74.What type does
sizehave in<Avatar size="40" />versus<Avatar size={40} />? - 75.What does
<input disabled={false} />render?