Guest User

Untitled

a guest
Feb 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. const useNormalizedApi = () => {
  2. let db = useDB();
  3.  
  4. return {
  5. ...
  6. fetchTodos: async () => {
  7. let todos = await api.fetchTodos();
  8. let { result, entities } = normalize(
  9. todos,
  10. apiSchemas.fetchTodosResponseSchema
  11. );
  12. db.mergeEntities(entities); // Indexed todo data
  13. db.updateStoredQuery('ALL_TODOS', result); // List of todo ids
  14. },
  15. ...
  16. };
  17. };
  18.  
  19. const TodosComponent = (props) => {
  20. let db = useDB();
  21.  
  22. let allTodosQuery = db.getStoredQuery('ALL_TODOS');
  23. let todos = db.executeQuery(allTodosQuery);
  24.  
  25. return (
  26. <JSON data={todos} />
  27. )
  28. }
Add Comment
Please, Sign In to add comment