0
votes

Minified React error #185; visit https://reactjs.org/docs/error-decoder.html?invariant=185 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

I've got this error when deployment

I heard this error can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate.

But in my component I don't have componentWillUpdate and componentDidUpdate.

why is it happening in my component?

this is my state init.

 constructor(props) {
    super(props);
    this.state = {
      isLoggedIn: false,
      loading:false,
      username:"",
      password:"",
      message:"",
      alert:{
      open: false,
      type: "",
      message: ""
    }
    this.handleClose = this.handleClose.bind(this);
    this.handleChange = this.handleChange.bind(this);
    this.handleFormSubmit = this.handleFormSubmit.bind(this);

and this is my handlers

handleClose(event, reason){
      if (reason === "clickaway") {
        return;
      }
      this.setState(prevState => ({
        alert: {
          ...prevState.alert, open:false
        }
      }));
  
  }
  
  handleFormSubmit(e) {
    e.preventDefault();
    this.setState({loading:true})
    this.Auth.login(this.state.username, this.state.password)
      .then((res) => {
        if(res.status == 200){
          localStorage.setItem("username", this.state.username);          
          var ec2Ready = setInterval(()=>{
            this.Auth.checkStatus(this.state.username)
            .then((res)=>{
                if(res.ready == true){
                  this.setState({loading:false, isLoggedIn:true})
                  clearInterval(ec2Ready)
                }else{
                  this.setState(prevState=>({
                    ...prevState, message: res.msg
                  }))
                }
            })
          }, 8000)
        }else{  
          this.setState({
            loading:false,
            alert:{ open: true, message:res.err, type:"error"}
        });
        
        }      
      })
      .catch((err) => {
        this.setState({
          loading:false,
          alert:{ open: true, message:err.response.statusText, type:"error"}
      });
  })
  
}

  handleChange(e) {
    this.setState({
      [e.target.name]: e.target.value,
    });
  }
}
1

1 Answers

-1
votes

#185 text: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

So, in non-technical terms - too many things may be loading into the page and to prevent infinite looping, react is saying it's got too much to handle.