componentDidUpadate Infinite loop with auth0 isAuthenticated

Viewed 88

I need to wait user data from auth0 api, to setState. I try to do this with componentDidUpdate, but i have an infinite loop What's wrong in this code ? :

    class App extends React.Component {

  constructor(props) {
    super(props);
    const { user } = this.props.auth0;


    // Context state
    this.state = {
      races: {},
      regions: {},
      allAnnonces: {},
      profile: {}
    }
  }
  componentDidMount() {
    const user = this.props.auth0.user;
 console.log("componentDidMount",this.props.auth0.isAuthenticated);
  }

  componentDidUpdate(prevProps) {
    const isAuthenticated = this.props.auth0.isAuthenticated;

    if (prevProps.isAuthenticated != isAuthenticated) {
      this.setState({ userInfos: "test" });
    }
  }


  render() {
  if (isLoading) {
      return <Loading />;
    }

    return (
     <>hello</>
    )
   }

Here the Auth0 props :

enter image description here

1 Answers

Did you maybe mean

const isAuthenticated = this.props.auth0.isAuthenticated; ?

Related