反应本机回调值不能设置为状态,有错误,请帮助我解决

发布于 2025-02-01 01:10:10 字数 1777 浏览 1 评论 0原文

反应本机回调值无法设置为状态,有错误,请帮助我解决

    //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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文