R
R
real22102018-10-03 16:07:27
React
real2210, 2018-10-03 16:07:27

ReactRouterv4 and componentDidMount?

The crux of the matter is what.
There is a regular route:

<Route exact path='main/:iduser' component={UserOffice} />

There is a normal link: in the component in the componentDidMount () method, for example, a fetch occurs in the database. the bottom line is that the UserOffice component is mounted only once, and then only the props change if we change only the params in the url . What is the way out to pull a new user along a new param?
<Link to='main/123' />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-03
@real2210

componentDidUpdate(prevProps) {
  if (this.props.match.params.iduser !== prevProps.match.params.iduser) {
    this.fetchUserData();
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question