React-Admin:我们如何从 `authProvider` 代码中分派 store 操作? [英] React-Admin: How can we dispatch a store action from within the `authProvider` code?

查看:39
本文介绍了React-Admin:我们如何从 `authProvider` 代码中分派 store 操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AUTH_LOGIN 的异步获取中 我们希望在从其他端点(除了登录端点之外,例如我们调用另一个端点)获取数据之后分派一个动作为帐户带来数据等).

In the async fetch of the AUTH_LOGIN we want to dispatch an action after we fetch data from additional endpoints (apart from the login endpoint, for example we call another endpoint to bring data for the account, etc.).

我们已经准备好了(action、reducer、使用了 combineReducers 等),但是我们不确定如何在 authClient.js 中连接"authClient 函数 文件,因为这不是一个 component 以便使用 connect 功能.

We have all in place (action, reducer, used the combineReducers, etc.), but we are not sure how we can "connect" the authClient function in the authClient.js file, as this is not a component in order to use the connect function.

那我们如何dispatch一个动作呢?

How could we dispatch an action then?

推荐答案

正如你在 身份验证副作用,你的authClient返回的数据将被设置为USER_LOGIN_SUCCESS 操作将在 authClient 解析时自动分派.

As you can see in the authentication side effect, the data returned by your authClient will be set as the payload of the USER_LOGIN_SUCCESS action which will be dispatched automatically when the authClient resolve.

要将任何逻辑应用于身份验证有效载荷并最终调度一些自定义操作,您必须创建一个 自定义传奇 将对USER_LOGIN_SUCCESS 操作做出反应.

To apply any logic to the authentication payloa and eventually dispatch some custom actions, you'll have to create a custom saga which will react to USER_LOGIN_SUCCESS actions.

我们绝对应该在文档中添加一个示例

We should definitely add an example in the documentation

这篇关于React-Admin:我们如何从 `authProvider` 代码中分派 store 操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆