【问题标题】:React-admin how show notification about error from serverReact-admin 如何显示来自服务器的错误通知
【发布时间】:2021-02-08 18:01:40
【问题描述】:

反应管理员: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 仅显示“服务器错误”,我如何输出此消息

【问题讨论】:

    标签: javascript reactjs react-admin


    【解决方案1】:

    我不知道在 v2.9.5 上,但在最新版本中,您可以像这样使用 onSuccessonFailure 回调

    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>
    );
    

    【讨论】:

      猜你喜欢
      • 2019-07-02
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多