Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const useNormalizedApi = () => {
- let db = useDB();
- return {
- ...
- deleteTodo: async (id) => {
- let todo = await api.deleteTodo(id);
- let { result, entities } = normalize(
- todo,
- apiSchemas.deleteTodoResponseSchema
- );
- db.mergeEntities({
- Todo: {
- [id]: {
- isDeleted: true
- }
- }
- });
- db.updateStoredQuery(
- 'ALL_TODOS',
- (prevArray) => prevArray.filter(todoId => todoId != id)
- );
- },
- ...
- };
- };
- 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