mirror of
				https://gitlab.com/ceda_ei/sonzai.git
				synced 2025-11-04 09:00:05 +01:00 
			
		
		
		
	Add transformer to transform Date.
This commit is contained in:
		@@ -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);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user