Question · JavaScript and React course · Module 4: Context API and useReducer

Lazy Initialization

How do you implement lazy initialization in useReducer?

Answer options

  • Pass a function as the third parameter of useReducer
  • Use useEffect to initialize state
  • Pass a function instead of a value as initialState
  • Use useMemo to calculate the initial state

You can check the correct answer by solving this task in the CodeWorlds game.