Question · JavaScript and React course · Module 5: useEffect and Custom Hooks
State in Custom Hooks
What happens when two different components call the same custom hook (e.g., useToggle)?
Answer options
- Both components share the same state - a change in one affects the other
- Each component gets its own independent copy of the hook state
- React throws an error - a hook can only be used in one component
- State is shared only if components have the same parent
You can check the correct answer by solving this task in the CodeWorlds game.