setting State from render const

后端 未结 1 1386
感情败类
感情败类 2021-01-28 03:59

I would like to setState, in my case, feedbackLogId, which is required to called a function that will GET the details of feedback according to the feedbackLog

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 04:36

    Try to use getDerivedStateFromProps

    static getDerivedStateFromProps = (props, state) => { 
        console.log('props',props.navigation)
        const feedbackLogId = props.navigation.getParam('value', 'nothing');
        if(feedbackLogId){
        this.getPendingDetails(feedbackLogId);
        }
      }  
    

    In your constructor

     this.getPendingDetails = getPendingDetails.bind(this) 
    

    to

     this.getPendingDetails = this.getPendingDetails.bind(this)
    

    0 讨论(0)
提交回复
热议问题