Closed KashubaK closed 1 year ago
Hooks
useQuery
useMutation
useInstance
RootStoreProvider
RootStore
Currently we generate mutation/query classes. I'd like to abstract the direct implementation of those classes, for example:
import { useQuery, useInstance, useMutation } from 'mobx-depot'; import { AllTodosQuery } from '~/models/queries/AllTodosQuery'; import { CreateTodoMutation } from '~/models/mutations/CreateTodoMutation'; import { TodoModel } from '~/models/TodoModel'; function Todos() { const { loading, data } = useQuery(AllTodosQuery, { sortBy: 'dateCreated' }); data?.todos; // -> TodoModel[] | undefined; const newTodo = useInstance(TodoModel, { title: '', content: '' }); const { loading, data, mutate } = useMutation(CreateTodoMutation); const handleSubmit = async () => { const data = await mutate({ todo: newTodo }); data.todo; // -> TodoModel, ideally same reference as newTodo...? (sounds hard!) } }
Hooks
useQuery
useMutation
useInstance
RootStoreProvider
(other hooks will need access to theRootStore
)Currently we generate mutation/query classes. I'd like to abstract the direct implementation of those classes, for example: