I
I
iMishaKor2020-11-16 16:32:51
React
iMishaKor, 2020-11-16 16:32:51

ReactJS using useEffect hook, how to properly use dependency?

Hello!
Tell me what I'm doing wrong, here is a simple piece of code

...
  const userId = +props.match.params.userId || props.userId;
  useEffect(() => {
    props.getProfile(userId);
    props.getProfileStatus(userId);
  }, [userId]);
  ...

What the chrome dev tool swears at (not an error, but a warning):
React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array. However, 'props' will change when *any* prop changes, so the preferred fix is ​​to destructure the 'props' object outside of the useEffect call and refer to those specific props inside useEffect react-hooks/exhaustive-deps

As a dependency, I tried to use [props.match.params.userId, props.userId]
Although this is not a critical error, I would still like to figure out what I'm doing wrong

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question