title: React hooks useMemo/useCallback skip
body: <p>How can I use <code>useMemo</code>'s or <code>useCallback</code>'s seconds argument to optimize based on a value inside the callback?</p>
  
  <pre><code>const [s, setS] = useState({ page: { title: 'a', index: 3 } });
  const getPage = data =&gt; data.page;
  
  const cb = useCallback(data =&gt; setS(data), [getPage(data)]);
  //                                          ^ ain't no data here :(
  
  useEffect(() =&gt; externalService.sub(cb));
  </code></pre>
  
  <p>Basically I want to pass the callback to an external service but I want the <code>setSomeState</code> only be called if the <code>data.page</code> has been changed.</p>
  
  <p>I know I can wrap <code>setS</code> with another function and do a <code>shallowEqual</code> before calling it but was wondering if <code>useMemo</code> or <code>useCallback</code> provide something similar. </p>