M
M
maestro072022-02-09 18:11:34
React
maestro07, 2022-02-09 18:11:34

How to fix warning?

React Hook useEffect has a missing dependency: 'loadUsingHistory'. Either include it or remove the dependency array react-hooks/exhaustive-deps

useEffect(() => {
    loadUsingHistory();
  }, []);

  const loadUsingHistory = () => {
    if (id && !isNaN(+id)) {
      contract
        .getContractHistoryStatus(+id)
        .then((response) => {
          return response.data.map((item: any) => {
            return {
              ...item,
              key: item.id,
            };
          });
        })
        .then((response) => {
          setData(response);
        });
    }
  };

...
        <Button icon={<SyncOutlined />} onClick={loadUsingHistory}>
          Обновить
        </Button>


in my component, I want to dump the list using axios and render it.
there is also a button that causes unloading.

Why add dependencies to the list if I only need to call load on mount at the beginning?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2022-02-09
@Alexandroppolus

const loadUsingHistory = useCallback(() => {
    ...
}, [id, setData]);

useEffect(() => {
    loadUsingHistory();
}, [loadUsingHistory]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question