React.js · Intermediate

Using it: picking the right tool and applying it correctly.

Intermediate·4.2.1

Compared to the class-component lifecycle, when does a `useEffect` with no dependency array run relative to `componentDidMount` and `componentDidUpdate`?

Intermediate·4.2.2

Two sibling components both need access to the same piece of state, but there's no existing parent holding it. What is the standard React pattern for this?

Intermediate·4.2.3

What is the purpose of the function you can optionally return from inside a `useEffect` callback?

Intermediate·4.2.4

What problem does "prop drilling" describe?

Intermediate·4.2.5

What problem is React's Context API primarily designed to solve?

Intermediate·4.2.6

What is a "synthetic event" in React?

Intermediate·4.2.7

In legacy (pre-React-18) behavior, if you call two separate `setState`/state-setter updates inside a single React event handler (like an onClick), what typically happens?

Intermediate·4.2.8

When rendering a list of items with `.map()`, why is using the array index as the `key` prop often discouraged?

Intermediate·4.2.9

For a controlled text input, which pattern correctly keeps the input's displayed value in sync with React state?

Intermediate·4.2.10

What is a basic, legitimate use case for `useRef` at this stage?

Intermediate·4.2.11

What's the practical tradeoff between wrapping sibling elements in a `<div>` versus a `<React.Fragment>` (`<>...</>`)?

Intermediate·4.2.12

What is PropTypes (or a TypeScript prop interface) used for in React?

Intermediate·4.2.13

What does `useReducer` provide that plain `useState` doesn't, at a basic level?

Intermediate·4.2.14

What is the idiomatic way for a child component to notify its parent that something happened (e.g. a button was clicked inside the child)?

Intermediate·4.2.15

In a function component, what's the equivalent of a class component's `componentDidUpdate` (code that should run after specific props or state change, but not on the very first render)?

Intermediate·4.2.16

At a conceptual level, what is a React error boundary for?

Intermediate·4.2.17

How do you read a value provided by a `Context.Provider` inside a function component?

Intermediate·4.2.18

If a `useEffect` has an empty dependency array `[]`, when does its effect function run?

Intermediate·4.2.19

Why does calling a state setter (e.g. from `useState`) not update the variable's value immediately, synchronously, in the very next line of code after calling it?

Intermediate·4.2.20

What does it mean that JSX "compiles down to" `React.createElement` calls?