Post

Hoisting state is so often the answer, but many devs avoid it because they want co-location. Underrated solution: Export a hook alongside the component. Import and use the hook in a parent, pass the returned state down. Now parent owns the state and can interact with it, but logic is co-located.

I've seen so many creative solutions to avoid hoisting, like mutating refs, misusing useImperativeHandle, syncing state in effects etc, etc, often leading to hard to catch bugs. Just hoist it.

0 reposts2 likes

No replies yet.