Created
February 17, 2019 00:30
-
-
Save malerba118/8a52d13b62af4dafa5f8fed5d2182cb3 to your computer and use it in GitHub Desktop.
Creating a Todo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useNormalizedApi = () => { | |
let db = useDB(); | |
return { | |
... | |
addTodo: async (text) => { | |
let todo = await api.addTodo(text); | |
let { result, entities } = normalize( | |
todo, | |
apiSchemas.addTodoResponseSchema | |
); | |
db.mergeEntities(entities); // Merge new todo data into database | |
db.updateStoredQuery('ALL_TODOS', (prevArray) => [...prevArray, todo.id]); | |
}, | |
... | |
}; | |
}; | |
const TodosComponent = (props) => { | |
let db = useDB(); | |
let allTodosQuery = db.getStoredQuery('ALL_TODOS'); | |
let todos = db.executeQuery(allTodosQuery); | |
return ( | |
<JSON data={todos} /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment