title: Can't perform React state update on an unmounted component for useCallback
body: <p>Sometimes I get an error and the full error message is:
  &quot;<em>Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.</em>&quot;</p>
  <p>What is the best way to fix this? This is my code:</p>
  <pre><code>const CustomRefresh = (props) =&gt; {
    const {
      isCurrent, isScheduled
    } = props;
    const [refreshing, setRefreshing] = useState(false);
  
    const inventoryContext = useContext(inventoryContext);
  
    const onRefresh = React.useCallback(async () =&gt; {
      setRefreshing(true);
  
      if (isCurrent) {
        await inventoryContext.refreshToday();
      }
  
      if (isScheduled) {
        await inventoryContext.refreshScheduled();
      }
  
      setRefreshing(false);
    }, [refreshing]);
  
    return (
      &lt;CustomRefresh refreshing={refreshing} style={style} onRefresh={onRefresh}&gt;
        {children}
      &lt;/CustomRefresh&gt;
    );
  };
  </code></pre>