Проблема с редиректом в React

Если userId нет, то нужно сделать редирект на другую страницу.

class ProfileClass extends React.Component {

  componentDidMount() {
    let userId = this.props.match.params.userId;
    if (!userId) {
      userId = this.props.userId
    }
    this.props.getUserProfile(userId);
  }

  render() {
    if (!this.userId) return <Navigate to='/login' />
    return <Profile {...this.props} />
  }
}

Проблема в том, что метод render выполняется раньше чем componentDidMount. Как поступить?


Ответы (0 шт):