我有多種模式用於註冊,並且遇到問題。我總共有三個動作。首先註冊按鈕,然後激活第一個註冊模式,以註冊谷歌或Facebook,然後完成模式的附加信息,無法由提供商收集將出現預填充輸入收集形式提供商。我在呈現應用程序時呈現兩種模式,並且只在單擊註冊按鈕時才顯示它。我需要在完成Facebook或Google登錄後調用componentDidMount,但在應用程序拳頭啓動時呈現模態時會調用它。這些按鈕打擊動作減速器和減速器,以改變布爾型的狀態以顯示模式。爲什麼我重新渲染時不會調用componentDidMount?
class HeaderRegisterButton extends Component {
render() {
return(
<div>
<Register1/>
<Register2/>
</div>
);
}
}
註冊模態1
class Register1 extends Component {
render() {
return(
<div>
<button onClick={() => this.props.showRegister2()} /> //This would hit the action reducer to get initial info and change the bool to show register 1 to false and register 2 to true.
</div>
);
}
}
註冊模態2
import { reduxForm, Field, initialize } from 'redux-form';
class Register2 extends Component {
componentDidMount() {
hInitalize() //only called when the app fires, not when the state changes in the action reducer to change bool to show this modal.
}
hInitalize() {
var initData = {};
const initData = {
"name" = this.props.name//name stored inside redux store
};
this.props.initialize(initData)
}
render() {
return(
<div>
//Code to display the modal which works.
</div>
);
}
}
'componentDidMount'只調用一次,而不是每次重新渲染。這將是'componentDidUpdate'。 – Li357
正是我所需要的! – joethemow
@AndrewLi這實際上創建了一個問題,我無法輸入任何輸入/表格 – joethemow