import { useCallback, useState } from 'react' // simplified version of react-query useMutation export const useMutation = , R>( fn: (...props: T) => Promise, options?: { onSuccess?: (data: R) => void onError?: (error: unknown) => void } ) => { const { onSuccess, onError } = options ?? {} const [isLoading, setLoading] = useState(false) const [error, setError] = useState(null) const [data, setData] = useState(null) const mutate = useCallback( async (...props: T) => { setLoading(true) setError(null) try { const data = await fn(...props) setData(data) onSuccess?.(data) return data } catch (error) { setError(error) onError?.(error) } finally { setLoading(false) } }, [fn, onError, onSuccess] ) return { mutate, data, isLoading, error } }