Converting a regular reducer to undoable reducer
This example shows how to convert a regular reducer to undoable reducer.
We will create an application that implements github labels(the ones we add to the github issues).
// ./src/reducer.js
import undoable from 'redux-undo';
const initialState = {
labels: []
};
function reducer(state = initialState, action) {
switch(action.type) {
case 'ADD_LABEL':
return {
...state,
labels: [...state.labels, {
id: action.id,
name: action.name,
color: action.color,
description: action.description
}]
}
case 'DELETE_LABEL':
return {
...state,
labels: state.labels.filter(label => label.id !== action.id)
}
default:
return state;
}
}
// Calling an undoable with our regular reducer gives an undoable reducer
export default undoable(reducer);./src/index.js
Last updated
Was this helpful?