11import { useState } from 'react' ;
2- import { useCreateEntity , useDeleteEntity , useQuery , useUpdateEntity } from '../schema' ;
2+
3+ import { useCreateEntity , useDeleteEntity , useQuery , useUpdateEntity } from '@graph-framework/schema' ;
4+
5+ import { Todo } from '../schema' ;
36import { Button } from './ui/button' ;
47import { Input } from './ui/input' ;
58
69export const TodosApp = ( ) => {
7- const createEntity = useCreateEntity ( ) ;
8- const updateEntity = useUpdateEntity ( ) ;
10+ const todos = useQuery ( Todo ) ;
11+ const createEntity = useCreateEntity ( Todo ) ;
12+ const updateEntity = useUpdateEntity ( Todo ) ;
913 const deleteEntity = useDeleteEntity ( ) ;
10- const todos = useQuery ( { types : [ 'Todo' ] } ) ;
1114 const [ newTodoTitle , setNewTodoTitle ] = useState ( '' ) ;
1215
1316 return (
@@ -17,10 +20,7 @@ export const TodosApp = () => {
1720 < Input type = "text" value = { newTodoTitle } onChange = { ( e ) => setNewTodoTitle ( e . target . value ) } />
1821 < Button
1922 onClick = { ( ) => {
20- createEntity ( {
21- types : [ 'Todo' ] ,
22- data : { name : newTodoTitle , completed : false } ,
23- } ) ;
23+ createEntity ( { name : newTodoTitle , completed : false } ) ;
2424 setNewTodoTitle ( '' ) ;
2525 } }
2626 >
@@ -33,13 +33,7 @@ export const TodosApp = () => {
3333 < input
3434 type = "checkbox"
3535 checked = { todo . completed }
36- onChange = { ( e ) =>
37- updateEntity ( {
38- id : todo . id ,
39- types : [ 'Todo' ] ,
40- data : { completed : e . target . checked } ,
41- } )
42- }
36+ onChange = { ( e ) => updateEntity ( todo . id , { completed : e . target . checked } ) }
4337 />
4438 < Button onClick = { ( ) => deleteEntity ( todo . id ) } > Delete</ Button >
4539 </ div >
0 commit comments