mirror of https://gitlab.com/ceda_ei/sonzai.git
Add transformer to transform Date.
This commit is contained in:
parent
83d0310bdc
commit
dedf976c95
|
@ -1,11 +1,20 @@
|
||||||
import { createStore } from "redux";
|
import { createStore } from "redux";
|
||||||
import { persistStore, persistReducer } from "redux-persist";
|
import { persistStore, persistReducer, createTransform } from "redux-persist";
|
||||||
import AsyncStorage from "@react-native-community/async-storage";
|
import AsyncStorage from "@react-native-community/async-storage";
|
||||||
import rootReducer from "./reducers";
|
import rootReducer from "./reducers";
|
||||||
|
|
||||||
|
function decode(toRehydrate) {
|
||||||
|
return JSON.parse(toRehydrate, (_, value) => {
|
||||||
|
if (typeof value === "string" && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/))
|
||||||
|
return new Date(value);
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: "root",
|
key: "root",
|
||||||
storage: AsyncStorage,
|
storage: AsyncStorage,
|
||||||
|
transforms: [createTransform(JSON.stringify, decode)],
|
||||||
};
|
};
|
||||||
|
|
||||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||||
|
|
Loading…
Reference in New Issue