Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const useNormalizedApi = () => {
- let db = useDB();
- return {
- ...
- fetchTodos: async () => {
- let todos = await api.fetchTodos();
- let { result, entities } = normalize(
- todos,
- apiSchemas.fetchTodosResponseSchema
- );
- db.mergeEntities(entities); // Indexed todo data
- db.updateStoredQuery('ALL_TODOS', result); // List of todo ids
- },
- ...
- };
- };
- const TodosComponent = (props) => {
- let db = useDB();
- let allTodosQuery = db.getStoredQuery('ALL_TODOS');
- let todos = db.executeQuery(allTodosQuery);
- return (
- <JSON data={todos} />
- )
- }
Add Comment
Please, Sign In to add comment