Can i have a function inside a state in react?

后端 未结 2 1095
面向向阳花
面向向阳花 2021-01-17 12:23

I\'m trying to create variables and a function inside a state like this

     state = {
          modalVisible: false,
          photo:""
          g         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 12:53

    Yes you can.

    class App extends Component {
        func1 = () => {
            this.setState({flag:!this.state.flag})
        }
       state = {
           flag:true,       
           doclick:this.func1
        }
    } 
    

提交回复
热议问题