每次用户在react-admin中进行身份验证时,我都需要从自定义缩减程序中分派一个操作。根据这篇文章React-Admin: How can we dispatch a store action from within the authProvider code?,因为我不能访问我的身份验证提供者内部的redux商店,所以我必须创建一个传奇
这是我的代码:
// index.ts
function App() {
return (
<Admin
dataProvider={dataProvider}
authProvider={authProvider}
customReducers={{ myReducer }}
customSagas={[authSaga]}
>
[...]
</Admin>
);
}
// authSaga.ts
import { put, take } from "redux-saga/effects";
import { USER_LOGIN_SUCCESS } from "ra-core";
import { showNotification } from "react-admin";
const authSaga = function* () {
while (true) {
console.log("SAGA RUNNING");
yield take(USER_LOGIN_SUCCESS);
// This never runs
console.log("USER_LOGIN_SUCCESS RUNNING");
yield put(showNotification("TEST"));
}
};
export default authSaga;我可以在控制台中看到消息"SAGA RUNNING",但当用户进行身份验证时,第二个日志不会运行。我尝试使用USER_LOGIN_SUCCESS常量,也尝试使用"USER_LOGIN_SUCCESS“。我也尝试过使用takeEvery,但都不起作用。"authSaga“指向的是我的传奇,而不是react-admin中包含的那个。这是我第一次使用redux-saga,所以我可能遗漏了一些东西。有什么想法吗?
发布于 2021-11-08 09:13:53
在我看来,操作USER_LOGIN_SUCCESS很久以前就被禁用了,它在我的应用程序中也不会发生,请尝试使用REGISTER_RESOURCE / UNREGISTER_RESOURCE。请注意,将对您的每个资源执行REGISTER_RESOURCE / UNREGISTER_RESOURCE操作。
https://stackoverflow.com/questions/69878781
复制相似问题