在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ react父組件通過props更新了子組件的state,同時觸發(fā)子組件的acti

react父組件通過props更新了子組件的state,同時觸發(fā)子組件的action只觸發(fā)一次

我的代碼是這么寫的,我想要在我的父級組件通過props更新了子組件的state后只執(zhí)行一次子組件的action。請問 我這么寫是正確的么?

這么寫我的action 會一直循環(huán)執(zhí)行

componentWillReceiveProps(nextProps) {
        this.setState({
            index: nextProps.selectType
        }, () => {
            // this.props.actions.submitAppealTypeFn(this.state);
        });
    }

父組件的代碼

class FillName extends Component {
    constructor(props) {
        super(props);

        this.state = {
            selectType: ''
        };
    }

    handleSelectType(type) {
        this.setState({
            selectType: type
        });
    }




    render() {
        const {fillAppealName, actions} = this.props;
        console.log(this.state);
        return (
            <div className="component-fillaccount">
                <Header/>
                <StepFillName
                    {...this.state}
                    actions={actions}/>
                <Footer/>
                <AlertForm
                    handleSelect={this.handleSelectType.bind(this)}
                    stateObj={fillAppealName}
                    actions={actions}/>
            </div>
        );
    }
}
回答
編輯回答
雨萌萌

為什么action會從props中傳進來,然后你需要貼出父控件如何傳遞props的代碼

其實我是想知道你的action具體是操作了什么,因為的你循環(huán)很顯然是

父 render-> action傳遞給子 -> 子willreceive中又操作了action,action又影響的父重新render,然后就有了循環(huán)。

2017年8月16日 19:06
編輯回答
雨萌萌

樓主這個問題怎么解決的?

2017年6月17日 15:17