Skip to content

useMutation ​

Category
Utilities

Hook that defines the logic when mutate data

typescript
import { useMutation } from '@siberiacancode/reactuse';

Usage ​

typescript
const { mutate, mutateAsync, isLoading, isError, isSuccess, error, data } = useMutation((name) => Promise.resolve(name));

Demo ​

Api ​

Parameters

NameTypeDefaultNote
callback(body: Body) => Promise<Data>-The callback function to be invoked
options.retry?boolean | number-The retry count of requests
options.onSuccess?(data: Data) => void-The callback function to be invoked on success
options.onError?(error: Error) => void-The callback function to be invoked on error

Contributors ​

Source • Demo