Design Patterns · Junior · Question 37 of 75
What pattern does a custom hook useWindowSize() implement?
- ✓Correct answer: Reusing stateful logic without changing the component tree
- 2Creating a single browser window instance (Singleton)
- 3Inheriting the component from a base
Windowclass viaextends
Explanation
Hooks replaced HOCs and render props for reusing logic: the component calls a function and gets data without piling up wrappers. Inside, the hook subscribes to resize and unsubscribes itself (the Observer pattern).