can props be used in a useEffect?

Viewed 42

I have a question that is if you can use props inside useEffects

enter image description here

1 Answers

Yes. Props can be used in useEffect hook. Props are just values, when it is used in a useEffect dependency array, the component will re-render.

// This will only re-run if the value of `props.count` changes
useEffect(() => {
  fetchSomeData(props.count);
}, [props.count]);
Related