Question · JavaScript and React course · Module 4: Context API and useReducer
Memoizing Provider Values
Why is it worth wrapping the value object in a Provider with useMemo?
Answer options
- Because React doesn't allow passing objects as value without useMemo
- Because useMemo automatically synchronizes state between Providers
- To prevent creating a new object on every render, which would cause unnecessary re-renders of all consumers
- useMemo is required by React 18 for all contexts
You can check the correct answer by solving this task in the CodeWorlds game.