'use client'; import useAspidaSWR from '@aspida/swr'; import type { Task } from 'common/types'; import type { ChangeEvent, FormEvent } from 'react'; import { useCallback, useState } from 'react'; import { apiClient } from 'utils/apiClient'; import styles from './page.module.css'; export default function Home() { const { data: tasks, error, mutate } = useAspidaSWR(apiClient.tasks); const [label, setLabel] = useState(''); const inputLabel = useCallback( (e: ChangeEvent) => setLabel(e.target.value), [], ); const createTask = useCallback( async (e: FormEvent) => { e.preventDefault(); if (!label) return; await apiClient.tasks.post({ body: { label } }); setLabel(''); mutate(); }, [label, mutate], ); const toggleDone = useCallback( async (task: Task) => { await apiClient.tasks._taskId(task.id).patch({ body: { done: !task.done } }); mutate(); }, [mutate], ); const deleteTask = useCallback( async (task: Task) => { await apiClient.tasks._taskId(task.id).delete(); mutate(); }, [mutate], ); if (error) return
failed to load
; if (!tasks) return
loading...
; return ( <>

Welcome to Next.js!

frourio-todo-app

); }