You could do the following:
useEffect(() => {
fetchAdDetails(props.match.params && props.match.params.id);
getAllReviews(props.match.params && props.match.params.id);
}, []);
If you want to run an effect and clean it up only once (on mount and
unmount), you can pass an empty array ([]) as a second argument. This
tells React that your effect doesn’t depend on any values from props
or state, so it never needs to re-run.
https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…