Hacker News new | past | comments | ask | show | jobs | submit login

How would passing a value from one hook to another look like, for example, Subhook requiring viewport value to set up some subscription?



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)




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: