react hooks props in useEffect react hooks props in useEffect reactjs reactjs

react hooks props in useEffect


If the value of props.filters did not change, then React would skip the effect.

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

With hooks, React does this internally unlike the implementation using componentDidUpdate where we have to compare the value of prevProps and nextProps against each other.

See optimizing performance by skipping effects.