Answer the question
In order to leave comments, you need to log in
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]);
...
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question