title: Is it fine to use useCallback inside another function?
body: <p>I have (TypeScript) code like the following:</p>
  <pre><code>export const DemoComponent = React.memo((props: DemoComponentProps) =&gt; {
      const [state1, setState1] = React.useState&lt;string | undefined&gt;('');
      const [state2, setState2] = React.useState&lt;string | undefined&gt;('');
      const createF = (b: boolean) =&gt; React.useCallback(() =&gt; {
          /* code that does not depend on b or state2 */
  
          doSomething({ param: 'param', param2: b ? undefined : state2 });
  
          if (!b) setState2(/* some other value */);
      }, b ? [state1] : [state1, state2]);
      const f1 = createF(false);
      const f2 = createF(true);
  
      return (
          /* a few components, some of which use f1, while others use f2 */
      );
  });
  </code></pre>
  <p>Will <code>useCallback</code> work as expected here (as if I just wrote it twice for <code>f1</code> and <code>f2</code> and rewrote all places that use <code>b</code>) or will it go wrong?</p>