美文网首页
React componentWillReceiveProps

React componentWillReceiveProps

作者: 杜朝辉 | 来源:发表于2019-11-20 16:01 被阅读0次

在React Redux 开发场景下出现一个特殊情况:

在model中未定义的字段,通过 compcomponentWillReceiveProps 获得值是永远是相同的,且是异步获得值;

const Model: ModelType = {

    namespace: 'CustomerEditService',

    state: {
        ···
    },
    effects: {

        *fetch({ payload }, { call, put }) {
            const response = yield call(queryCustomer, payload);
            yield put({ type: 'save', payload: response.data.data, });
        },

     },

    reducers: {
        save(state, action) {
            return { ...state, ...action.payload, };
        }
    }
}

export default Model;

// eslint-disable-next-line react/sort-

compcomponentWillReceiveProps(nextProps: Readonly<CustomerFormProps>): void {    

    const { dictionaries: { area }, CustomerEditService: { sourceId } } = nextProps;    

    if (sourceId === this.props.CustomerEditService.sourceId) {        

        return     

    }   

    this.setState({ countries: area });

}

相关文章

网友评论

      本文标题:React componentWillReceiveProps

      本文链接:https://www.haomeiwen.com/subject/auboictx.html