();
const { data, refetch } = useGetList('posts');
const [deleteOne, { isLoading }] = useDelete();
const handleClick = () => {
deleteOne(
'posts',
{
id: 1,
previousData: { id: 1, title: 'Hello' },
},
{
mutationMode: 'undoable',
onSuccess: () => setSuccess('success'),
}
);
setNotification(true);
};
return (
<>
{data?.map(post => (
- {post.title}
))}
{notification ? (
<>
>
) : (
)}
{success && {success}
}
{isMutating !== 0 && mutating
}
>
);
};
export const ErrorCase = () => {
const posts = [
{ id: 1, title: 'Hello' },
{ id: 2, title: 'World' },
];
const dataProvider = {
getList: (resource, params) => {
console.log('getList', resource, params);
return Promise.resolve({
data: posts,
total: posts.length,
});
},
delete: (resource, params) => {
console.log('delete', resource, params);
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('something went wrong'));
}, 1000);
});
},
} as any;
return (
);
};
const ErrorCore = () => {
const isMutating = useIsMutating();
const [notification, setNotification] = useState(false);
const [success, setSuccess] = useState();
const [error, setError] = useState();
const { data, refetch } = useGetList('posts');
const [deleteOne, { isLoading }] = useDelete();
const handleClick = () => {
setError(undefined);
deleteOne(
'posts',
{
id: 1,
previousData: { id: 1, title: 'Hello World' },
},
{
mutationMode: 'undoable',
onSuccess: () => setSuccess('success'),
onError: e => {
setError(e);
setSuccess('');
},
}
);
setNotification(true);
};
return (
<>
{data?.map(post => (
- {post.title}
))}
{notification ? (
<>
>
) : (
)}
{error && {error.message}
}
{success && {success}
}
{isMutating !== 0 && mutating
}
>
);
};