我无法在react-native的静态方法中访问'this'关键字,当我尝试访问它时,它抛出了类似'this.setState not a function'之类的错误。
这是我的代码。
var parts = sentence.match(/\w+/g);
答案 0 :(得分:-1)
this
指向其他内容。
您需要从外部函数捕获this
。
static getShiftStatus = () =>{
var that = this; // capture here
Usermodal.getShiftStatus((isStatus) =>{
that.setState({isShiftStart: isStatus}) // use it here
console.log(a.state.isShiftStart)
})
}