Hacker News new | ask | show | jobs
by drabinowitz 2740 days ago
I wonder if it would makes sense to enforce hooks being called through a top level React function. To make some of the ordering more explicit

  function MyReactComponent() {
    const [
      [width, setWidth],
      [name, setName],
    ] = React.use(
      [useWidth],
      [useName, 'alice'],
    );
    return <div>{width} {name}</div>
  }
admittedly, this is much less clean looking than the current proposal, but, in my mind at least, it makes it a bit more clear that you have to pass the functions in with a specific order at the top of the component.
1 comments

I don't understand what exactly you're trying to solve by this (nothing prevents a user from making it conditional) but it definitely has flaw #7 (can't pass values between Hooks).
Ah that's fair about flaw #7