lundi 19 juin 2017

Redux - Checked checkbox wont change back on state change

I've got a table with rows that can be selected by clicking on a checkbox, so I decided to keep checkbox state in redux store. When I dispatch an action on a checkbox it changes correctly in redux-devtools but stays the same on page. Where could be a mistake?

My cell with checkbox:


    const columns = [
        {
            Header: 'ID',
            accessor: 'id',
            width: 40,
            filterable: false,
            Cell: (cell) => {

                return (
                    {cell.index + 1}
                         {
                                   let action = actions.visuals.visits.triggerCheckbox(cell.original.id, e.target.checked);

                                   return dispatch(action);
                               }}
                        />
                    
                )}
        }]

Trigger checkbox reducer:


    export default (state = data, action) => {
        switch (action.type) {
            case TRIGGER_CHECKBOX:
                let triggeredCheckbox = action.payload.checkboxId

                return {
                    ...state,
                    [triggeredCheckbox]: {
                        ...state[triggeredCheckbox],
                        checked: action.payload.checkboxState
                    }
                }
            default:
                return state
        }
    }




Aucun commentaire:

Enregistrer un commentaire