lodash debounce in React functional component not working

前端 未结 3 1798
日久生厌
日久生厌 2021-02-01 04:03

I have a functional component built around the React Table component that uses the Apollo GraphQL client for server-side pagination and searching. I am trying to implement debou

3条回答
  •  日久生厌
    2021-02-01 04:38

    You must remember the debounced function between renders.

    However, you should not use useCallback to remember a debounced (or throttled) function as suggested in other answers. useCallback is designed for inline functions!

    Instead use useMemo to remember the debounced function between renders:

    useMemo(() => debounce(loadData, 1000), []);
    

提交回复
热议问题