1

Understand dependency lists out all as soon as any of them is changed will run whatever in the useEffect. Mui-data-grid pagination demo, line 75, dependency has setRowCountState which is a function:

const [rowCountState, setRowCountState] = React.useState(rowCount || 0);
React.useEffect(() => {
    setRowCountState((prevRowCountState) =>
      rowCount !== undefined ? rowCount : prevRowCountState,
    );
  }, [rowCount, setRowCountState]);

If a reference execution is a trigger, it will then create an infinite loop which needs outCallBack. But it doesn't have one. So what a function in dependency array serves?

Update The suggested answer changes the function implementation which is not the case here. I'd like to point out that Not everyone has the same intellectual level, while answer A understood by person A, it may require answer B for person B. Vice versa. Appreciate it if this is not closed.

2
  • Does this answer your question? setState in React's useEffect dependency array Commented May 2, 2022 at 0:03
  • @cSharp Thanks for the suggestion. The suggested answer use a case of setState function changes implementation does not apply here. Commented May 4, 2022 at 23:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.