Why Do React Hooks Rely on Call Order? — overreacted
2 days ago
- React Hooks rely on persistent call index between re-renders to give state variables stable identity.
- Alternative proposals like keyed state cause name clashes, especially when custom Hooks are used.
- Custom Hooks are central to Hooks, but some alternatives prevent extracting them or force extra wrappers.
- The diamond problem (two Hooks using the same underlying Hook) is naturally resolved by call order.
- Copy-pasting code between components and custom Hooks is safe with call order, unlike keyed approaches.
- Passing values between Hooks is straightforward with function calls, enabling powerful compositions.
- Hooks avoid ceremony by being plain functions, simplifying debugging and static typing.
- The design is a tradeoff that optimizes for change, composition, and practical usage over theoretical purity.