Ich möchte den aktuellen Zustand eines bestimmten Reducers im Sitzungsspeicher speichern, ohne ihn bei jeder Aktion explizit aufzurufen.Redux reducer - on state change
const { handleActions } = require("redux-actions");
// How do i make this logic run on any state change without adding it to every action?
const onStateChange = (state) => sessionStorage.save(keys.myReducer, state);
const myReducer = handleActions
({
[Actions.action1]: (state, action) => (
update(state, {
prop1: {$set: action.payload},
})
),
[Actions.action2]: (state, action) => (
update(state, {
prop2: {$set: action.payload},
})
)
},
//****************INITIAL STATE***********************
{
prop1: [],
prop2: []
}
);
Gibt es eine Möglichkeit, das Statusänderungsereignis für einen bestimmten Reduzierer zu erfassen?
Ich kenne store.subscribe
, aber das ist für das gesamte Geschäft, ich spreche zu einer bestimmten Reduktions Änderung hört
Dank
Haben Sie Bibliotheken wie [redux-localstorage] (https://github.com/elgerlambert/redux-localstorage) oder [redox-persist] (https://github.com/rt2zz/redux-persist) ausprobiert? Oder adressieren Sie einen Nischen-Anwendungsfall, den diese Bibliotheken nicht adressieren? – excalliburbd
@excalliburbd - persisting der Staat ist nicht die einzige Logik, die ich auf Zustandsänderung ausführen möchte, so dass dies leider nicht das Problem löst – Daniel