3 ms·
How would passing a value from one hook to another look like, for example, Subhook requiring viewport value to set up some subscription?
by orangepanda 4y ago
How would passing a value from one hook to another look like, for example, Subhook requiring viewport value to set up some subscription?
- spion 4y agoGood 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)