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

Re-render Trap in Context API

What happens when one large context stores the ship position (updated 60x/s) and the fuel level, and a FuelGauge component reads only fuel?

Answer options

  • FuelGauge renders only when fuel changes - React optimizes this automatically
  • FuelGauge renders on every position change, even though it doesn't use that data
  • React throws an error because context cannot store multiple values
  • FuelGauge doesn't render at all because it's not a direct child of the Provider

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