如何解决React-admin如何显示来自服务器的错误通知
React-Admin:2.9.5
我有下一个代码
const CreateUserComponentBase = (props) => {
const { ...rest } = props
return (
<SimpleForm
validate={validate}
{...rest}
>
{/*...code*/}
</SimpleForm>
)
}
const UserCreateBase = (props: any) => {
const { setTitle,...rest } = props
return (
<Create {...rest}>
<CreateUserForm {...rest} isEdit={false} />
</Create>
)
};
我正在服务器上发送请求,并且我的API生成了一条错误消息,如果只有React-Admin显示“服务器错误”,该如何输出该消息
解决方法
我在v2.9.5上不知道,但是在最新版本中,您可以像这样使用onSuccess
和onFailure
回调
const handleFailure = (error) => {
notify(`Something bad happened: ${error}`),'error');
};
const handleSuccess = (data) => {
notify('Success!');
redirect('show',props.basePath,data.id);
refresh();
};
return (
<Edit
{...props}
onFailure={handleFailure}
onSuccess={handleSuccess}
>
...
</Edit>
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。