Put in order · JavaScript and React course · Module 12: React and TypeScript

Building Context + useReducer

Arrange the steps for creating a typed Context with useReducer in the correct order:

Items to put in order

  • Create a Provider with useReducer and pass state + dispatch
  • Create a custom hook with validation (throw Error when Provider is missing)
  • Create Context with createContext<ContextType | undefined>(undefined)
  • Write the reducer: (state: State, action: Action) => State
  • Define State interfaces and union type Action

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