Hacker News new | ask | show | jobs
by orangepanda 1185 days ago
How would passing a value from one hook to another look like, for example, Subhook requiring viewport value to set up some subscription?
1 comments

Good question.

  component.use(SubHook, param)
could be used, that would pass the param as a second argument to the constructor.

The main reason why this isn't the case, I think, is concurrent mode. Hooks force certain values to be retreived and stay stable during render (i.e. you can only get a component state value during render function) and this is important if there are multiple setup and teardowns going on.

(Concurrent mode is IMO a bit of unfortunate React complexity that a lot of users of React don't really need, and many others can avoid)