状态不会在渲染中更新。 + Redux

时间:2019-12-07 02:19:21

标签: reactjs redux

我已经被堆积了那么久。 我有以下显示了<Input />页和<Confirm />页的组件类。

我应该通过state.mode输入/确认来更新。

当我在<Input/>中进行调度时,它会减速并更新state.mode

class Sample extends Component {
    constructor(props){
        super(props);
        this.state = {
            mode: 'input',
            params: []
        }
    }

    render() {
        console.log('DEBGUG: ' + this.state.mode); //<-- Returns 'input', 'confirm' is expected.
        switch (this.state.mode) {
            case 'input':
                return (<InputForm />);
            case 'confirm':
                return (<ConfirmForm />);
            default:
                return (<InputForm />);
        }
    }
}
export default connect((state)=>state)(Sample);
    const initData = {
        mode: 'input'
    }
    export function sampleReducer(state = initData, action){
        switch (action.type) {
            case 'INPUT':
                return {mode: 'input'};
            case 'CONFIRM':
            return {mode: 'confirm'};
            default:
                return state;
        }
    }

我希望能够呈现并显示<Confirm />页面。 但是在渲染中,this.state.mode始终返回input

怎么了?

0 个答案:

没有答案