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.