反应本机回调值不能设置为状态,有错误,请帮助我解决
反应本机回调值无法设置为状态,有错误,请帮助我解决
//ERROR
//When callback values set to state i got an error
// WARN Possible Unhandled Promise Rejection (id: 0):
// TypeError: undefined is not an object (evaluating 'this.setState')
this.setState({Va_St_Data: cbDataResult.message});
va_body = json.stringify({cuscode:this.state.va_st_st_usercode,idno,idno:this.state.va_st_seridno, ;
Fun_Datafetch.call(this, Va_Body,"api/userlogin",function(cbDataResult) {
console.log('child : ' + cbDataResult.message);
//upto this line working fine
//output is : child : success/1
// Par : success/1
//*********** *
//ERROR
//When callback values set to state i got an error
// WARN Possible Unhandled Promise Rejection (id: 0):
// TypeError: undefined is not an object (evaluating
'this.setState')
this.setState({Va_St_Data: cbDataResult.message});
});
this.setState({Va_St_Loading: false });
};
export const Fun_Datafetch= (Va_Pa_Body, Va_Pa_UrlPart, callback) => {
try {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
fetch(REACT_APP_ENV_DB_URL + Va_Pa_UrlPart, {method: "POST", headers: myHeaders, body: Va_Pa_Body, })
.then(response => response.json())
.then((result) => {callback(result);
console.log('Par : ' + result.message);
}).catch(function(error) {
callback(error);
//console.log('Error : ' + error);
});
} catch (error) {
callback(error);
//console.log('Error : ' + error);
}
}
React Native callback values cant set to state, got an error please help me to solve
//ERROR
//When callback values set to state i got an error
// WARN Possible Unhandled Promise Rejection (id: 0):
// TypeError: undefined is not an object (evaluating 'this.setState')
this.setState({Va_St_Data: cbDataResult.message});
let Va_Body = JSON.stringify({ cuscode: this.state.Va_St_UserCode, idno: this.state.Va_St_UserIDNo, password: this.state.Va_St_UserPassword });
Fun_Datafetch.call(this, Va_Body,"api/userlogin",function(cbDataResult) {
console.log('child : ' + cbDataResult.message);
//upto this line working fine
//output is : child : success/1
// Par : success/1
//*********** *
//ERROR
//When callback values set to state i got an error
// WARN Possible Unhandled Promise Rejection (id: 0):
// TypeError: undefined is not an object (evaluating
'this.setState')
this.setState({Va_St_Data: cbDataResult.message});
});
this.setState({Va_St_Loading: false });
};
export const Fun_Datafetch= (Va_Pa_Body, Va_Pa_UrlPart, callback) => {
try {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
fetch(REACT_APP_ENV_DB_URL + Va_Pa_UrlPart, {method: "POST", headers: myHeaders, body: Va_Pa_Body, })
.then(response => response.json())
.then((result) => {callback(result);
console.log('Par : ' + result.message);
}).catch(function(error) {
callback(error);
//console.log('Error : ' + error);
});
} catch (error) {
callback(error);
//console.log('Error : ' + error);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论