i try it using setState
after function in react, first run function , function finished after run setState({example:'example1'})
, how i can do it,
click button run loaded Variable with this.setState({loaded:false})
, I will do the function setstate after the runtime this.setState({loaded:true})
, how can it be done with a technique, i will use other code
- container = () => { return (Balabla)} // is finish after 2.select
- this.setState({loaded:true})
export default class search extends React.Component {
constructor(props) {
super(props);
this.state = {
loaded:true
}
}
render(){
return(
<Loader loaded={this.state.loaded}/>
{this.container()}
)}
}
Probably you're asking for this, If I'm not wrong. You need an event-handler
( onClick
here) to call your respective function which changes the state. And also if your function is a paramless function, you shouldn't use the ()
in react
while calling it.
container = () => { this.setState({loaded:true})}
render(){
return(
<Loader loaded={this.state.loaded} onClick={this.container}/>
)}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.