Simple error handling trick to display error messages returned from a pocketbase server
const error = mutation?.error as ClientResponseError;
const pbError = error?.data?.data as Record<string, {message: string,code:string}>
useEffect(() => {
pbError&&Object?.entries(pbError)?.forEach(([key, value]) => {
form.setFieldMeta(key as any,(prev)=>{
return {...prev, errorMap:{
onChange:value?.message
}}
});
});
}, [pbError]);
Copied from a tanstack form discussion 👇