如何在onClick函数上更改存储在Redux上的布尔值?

时间:2017-12-11 16:56:50

标签: javascript reactjs redux onclick

我试图在Redux上做一个非常简单的更改状态,其中一个onClick事件存储在我的一个组件上,但我似乎无法弄明白。我在redux中设置了逻辑,动作和容器。

CONTAINER:

export const ReportTableContainer = connnect((state) =>({
    isOpen: state.app['modal-status']['isOpen']
}),() =>({FetchPopupReport}))(ReportTable)

组件功能:

onCellSelect = ({idx, rowIdx}) => {
    if(idx <= 2 && idx > 0){
        //where I want to change the state from false to true
    }else if(idx > 2){
        console.log('passed')
    }
}

REDUX文件:

export const logic = createLogic({
    type: FetchRoiReport,
    process({ getState, action, api}, dispatch, done) {
        dispatch(ModalStatus({isOpen: false}))
        dispatch(Loading({report: true}));
        api.get(URL)
        .then(obj => {
            dispatch(Loading({isOpen: false}));
            dispatch(FetchRoiReportSucceeded(obj))
            dispatch(ModalStatus({isOpen: false}));
            done();
        }).catch(err => {
            dispatch(Loading({isOpen: false}));
            dispatch(ModalStatus({status: false}));
            dispatch(FetchRoiReportFailed("ERROR"));
            done();
        })
        }
    });

我只想将.then()更改为true

1 个答案:

答案 0 :(得分:1)

我认为您必须从要更改将在商店调度的redux状态的地方调用一个操作,并且将调用reducer,最终将状态更改为“true”然后您的组件呈现会被称为。

就像在当前的'redux'文件中一样处理FetchRoiReport动作,然后在需要时调度Loading,FetchRoiReportSucceeded,ModalStatus。 reducer必须处理这些操作并改变状态(通过创建新状态)