A
A
Alexander2021-03-18 11:07:49
React
Alexander, 2021-03-18 11:07:49

How to rewrite componentDidUpdate to useEffect?

componentDidUpdate(prevProps: PropsType) {
    if (this.props.match.params.userId != prevProps.match.params.userId) {
      this.refreshProfile()
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan V, 2021-03-18
@axrising

useEffect(() => {
   refreshProfile()
}, [props.match.params.userId]);

If the value of props.match.params.userId hasn't changed, React won't fire useEffect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question