import { z } from 'zod' const noteSchema = z.object({ title: z.string(), description: z.string(), }) const submitNote = async (note: unknown, noteId: string | string[]) => { const parsedNote = noteSchema.safeParse(note) if (!parsedNote.success) return let response = { status: 200, message: 'Update', error: null, } await useFetch('/api/note', { method: 'POST', query: { id: noteId }, body: parsedNote.data, onResponse({ response }) { console.log('POST:', response._data.message) response = response._data }, }) return response } const deleteNote = async (noteId: string | string[]) => { let response await useFetch('/api/note', { method: 'DELETE', query: { id: noteId, }, onResponse({ response }) { console.log('DELETE:', response._data.message) response = response._data }, }) return response } type Note = z.infer const useNote = () => useState('note', () => Object({ title: '', description: '' })) const useDescription = () => useState('description', () => '') export { deleteNote, submitNote, useDescription, useNote }