Question · JavaScript and React course · Module 12: React and TypeScript

Default Value of createContext

Why is it recommended to use createContext<Type | undefined>(undefined) instead of providing a default object?

Answer options

  • Because undefined takes up less memory than an object
  • Because React requires undefined as the initial value
  • Because it forces error detection when a component is not inside a Provider
  • Because TypeScript does not support default objects

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