ReactContext API

50 items

1

The Prop Drilling Problem Context Solves

Slides / Video
2

Re-rendering Behavior of Context Consumers

Slides / Video
3

React.memo Won't Stop Context Re-renders

Code Quiz
4

Nesting and Overriding Providers

Slides / Video
5

Custom Consumer Hook for Context

Slides / Video
6

Creating a Custom Provider Component

Slides / Video
7

Context with useReducer

Slides / Video
8

Memoizing Context Provider Values

Slides / Video
9

Splitting Contexts to Minimize Re-renders

Slides / Video
10

Providing Context Values with Provider

Slides / Video
11

Creating Context with createContext

Slides / Video
12

Nested Providers and Shadowing

Code Quiz
13

Updating Context via State

Code Quiz
14

Context.Consumer Render Prop

Code Quiz
15

Passing Updaters Through Context

Code Quiz
16

Reading Context Outside the Provider

Code Quiz
17

Default Value Without a Provider

Code Quiz
18

Providing a Context Value

Code Quiz
19

Creating a Context

Code Quiz
20

Inverted Guard in Custom Context Hook

Code Quiz
21

Inline Context Value Re-renders

Code Quiz
22

Reducer Missing Default Case

Code Quiz
23

Swapped State and Dispatch Contexts

Code Quiz
24

displayName for DevTools

Quiz
25

Context Value Identity Pitfall

Quiz
26

Default Value in createContext

Quiz
27

Context.Consumer Render Prop

Quiz
28

Context Re-render Behavior

Quiz
29

Memoizing Context Value

Quiz
30

Context with useReducer

Quiz
31

Splitting Contexts

Quiz
32

Nested and Multiple Providers

Quiz
33

Overriding Context Values

Quiz
34

Custom Hook for Context

Quiz
35

When to Use Context

Quiz
36

Providing Context Values

Quiz
37

Creating a Context

Quiz
38

Context Limitations

Flashcard
39

Context displayName

Flashcard
40

Nesting and Overriding Providers

Flashcard
41

Re-render on Value Change

Flashcard
42

The value Prop

Flashcard
43

Providing a Context

Flashcard
44

Creating a Context

Flashcard
45

Context.Consumer Render Prop

Flashcard
46

Context with useReducer

Flashcard
47

Default Value in createContext

Flashcard
48

Custom useContext Hook

Flashcard
49

Splitting Contexts

Flashcard
50

Memoizing Context Value

Flashcard
Code QuizIntermediate

Passing Updaters Through Context

The increment function fires once at render instead of on click.

Codejavascript
const CounterContext = createContext();

function CounterProvider({ children }) {
  const [count, setCount] = useState(0);
  const increment = () => setCount(c => c + 1);
  return (
    <CounterContext.Provider value={{ count, increment: increment() }}>
      {children}
    </CounterContext.Provider>
  );
}

What is the bug in this code?