2021年1月27日星期三

React.js States not being set

I'm trying to pass some data from my App.js to another component, but in my other component, its not setting the state o. Does anyone know why the state isn't being set?

App.js

 getFourthAPIResponse() {                                                           axios.get('/api/ANDEFile/')          .then(res => this.setState({ andefilesrawdata: res.data }))      }  getA = (o) => {          this.setState({o: o})          this.setState({after: this.state.andefilesrawdata.filter(data => data.ANDEoutage == this.state.o)})  }  

Other Component:

buttonOutageHandle = (e) => {          e.preventDefault();           this.setState({o: e.target.value}, function () {              if (this.state.o != ''){                  this.props.getA(this.state.o)                  return this.setState({repA: this.props.after.map(data => data.ANDEpdf_local)})              }                       })           //this.setState({repA: [...this.props.andefilesrawdata.filter(x => x.ANDEoutage == this.state.o).map(x =>x.ANDEpdf_local)]})          console.log(e.target.name)            document.querySelector('.bg-modal-outage').style.display = 'block';      }  
https://stackoverflow.com/questions/65930375/react-js-states-not-being-set January 28, 2021 at 10:53AM

没有评论:

发表评论