[{"content":"When a redux powered react app starts to grow there is a comon use case: The need to reset a reducer\u0026rsquo;s state on specific events. Of course, handling the event in a new case inside the reducer returning its initial state is the obvious way to go.\nBut when the reducer is a combinedReducer, Having to edit each one of its aggregated reducers to makes them handle the reset event is a tedious and error prone process. One could easily forget to update one of them, now or during a future refactor.\nOne solution is to use the following Higher order reducer:\nconst (...resetOn) =\u0026gt; reducer =\u0026gt; (state, action) =\u0026gt; { if (resetOn.includes(action.type) { return reducer(undefined, action); } return reducer(state, action); } A reducer is a simple function deriving a state from an action. By forcing a call with undefined as its current state when the action\u0026rsquo;s type is one we want to reset on, the reducer will return its initialState.\nA simple use is the following one:\nconst resettableReducer = resettable( \u0026#39;FIRST_TYPE\u0026#39;, \u0026#39;SECOND_TYPE\u0026#39; )(originalReducer); ","date":"4 September 2018","externalUrl":null,"permalink":"/posts/a-resettable-reducer/","section":"Blog","summary":"","title":"A Resettable Reducer","type":"posts"},{"content":"","date":"4 September 2018","externalUrl":null,"permalink":"/posts/","section":"Blog","summary":"","title":"Blog","type":"posts"},{"content":"","date":"4 September 2018","externalUrl":null,"permalink":"/tags/javascript/","section":"Tags","summary":"","title":"Javascript","type":"tags"},{"content":"","date":"4 September 2018","externalUrl":null,"permalink":"/tags/react/","section":"Tags","summary":"","title":"React","type":"tags"},{"content":"","date":"4 September 2018","externalUrl":null,"permalink":"/tags/redux/","section":"Tags","summary":"","title":"Redux","type":"tags"},{"content":"","date":"4 September 2018","externalUrl":null,"permalink":"/tags/","section":"Tags","summary":"","title":"Tags","type":"tags"},{"content":"","date":"4 September 2018","externalUrl":null,"permalink":"/","section":"Yet Another Tech Blog","summary":"","title":"Yet Another Tech Blog","type":"page"},{"content":"","externalUrl":null,"permalink":"/authors/","section":"Authors","summary":"","title":"Authors","type":"authors"},{"content":"","externalUrl":null,"permalink":"/categories/","section":"Categories","summary":"","title":"Categories","type":"categories"},{"content":"","externalUrl":null,"permalink":"/photos/","section":"Photos","summary":"","title":"Photos","type":"photos"},{"content":"","externalUrl":null,"permalink":"/series/","section":"Series","summary":"","title":"Series","type":"series"}]