title: How do react hooks determine the component that they are for?
body: <p>I noticed that when I was using react hooks, a child component's state change does not rerender a parent component that had no state change. This is seen by this code sandbox: <a href="https://codesandbox.io/s/kmx6nqr4o" rel="noreferrer">https://codesandbox.io/s/kmx6nqr4o</a></p>
  
  <p>Due to the lack of passing the component to the hook as an argument, or as a bind context, I had mistakenly thought that react hooks / state changes simply triggered an entire application rerender, like how mithril works, and what React's <a href="https://reactjs.org/docs/design-principles.html#scheduling" rel="noreferrer">Design Principles</a> states:</p>
  
  <blockquote>
    <p>React walks the tree recursively and calls render functions of the whole updated tree during a single tick. </p>
  </blockquote>
  
  <p>Instead, it seems that react hooks know which component they are associated to, and thus, the rendering engine knows to only update that single component, and never call <code>render</code> on anything else, opposing what React's Design Principles document said above.</p>
  
  <ol>
  <li><p>How is the association between hook and component done?</p></li>
  <li><p>How does this association make it so that react knows to only call <code>render</code> on components whose state changed, and not those without? (in the code sandbox, despite child's state changing, the parent element's <code>render</code> is never called)</p></li>
  <li><p>How does this association still work when you abstract the usage of useState and setState into custom hook functions? (as the code sandbox does with the <code>setInterval</code> hook)</p></li>
  </ol>
  
  <p>Seems the answers lie somewhere with this trail <a href="https://github.com/facebook/react/blob/fef40c061ec7db03b6b0faa7608788d625cf78db/packages/react/src/ReactHooks.js#L16-L23" rel="noreferrer">resolveDispatcher</a>, <a href="https://github.com/facebook/react/blob/fef40c061ec7db03b6b0faa7608788d625cf78db/packages/react/src/ReactCurrentOwner.js" rel="noreferrer">ReactCurrentOwner</a>, <a href="https://github.com/facebook/react/tree/fef40c061ec7db03b6b0faa7608788d625cf78db/packages/react-reconciler" rel="noreferrer">react-reconciler</a>.</p>