Created
February 17, 2019 00:28
-
-
Save malerba118/dc6bbb461de546040497a7f1a5561e99 to your computer and use it in GitHub Desktop.
Updating 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 { | |
... | |
updateTodo: async (id, payload) => { | |
let todo = await api.updateTodo(id, payload); | |
let { result, entities } = normalize( | |
todo, | |
apiSchemas.updateTodoResponseSchema | |
); | |
db.mergeEntities(entities); | |
}, | |
... | |
}; | |
}; | |
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