UseState and useReducer return a state update function that is constant – the hook will always return the same function. UseFocusEffect has to assume that this new function’s behavior is different and what it does (on every render) is call the cleanup function unsubscribe. The pitfall is in how we tell React to render the JSX.

7m read timeFrom shopify.engineering
Post cover image
Table of contents
Functions That Expect Stable ValuesInline Functions That Return ComponentsComponent Memoization (But Don’t Call It That)More on React

Sort: