有一些数据来自每 5 秒的长轮询,我希望我的组件在每次数组的一项(或数组长度本身)发生变化时分派一个动作。在将数组作为依赖项传递给 useEffect 时,如何防止 useEffect 进入无限循环,但如果任何值发生更改,仍然设法调度某些操作?
useEffect(() => {
console.log(outcomes)
}, [outcomes])
Run Code Online (Sandbox Code Playgroud)
其中outcomes是一组 ID,例如[123, 234, 3212]. 数组中的项目可能会被替换或删除,因此数组的总长度可能 - 但不必 - 保持不变,因此outcomes.length作为依赖传递不是这种情况。
outcomes 来自 reselect 的自定义选择器:
const getOutcomes = createSelector(
someData,
data => data.map(({ outcomeId }) => outcomeId)
)
Run Code Online (Sandbox Code Playgroud) 我想在收到403错误时在axios拦截器中进行重定向.但是如何访问React组件之外的历史记录?
在React-Router v4中以编程方式导航,它位于React组件的上下文中,但是我在这里尝试axios上下文
axios.interceptors.response.use(function (response) {
// Do something with response data
return response;
}, function (error) {
// Do something with response error
if(error.response.status === 403) { console.log("Redirection needed !"); }
// Trow errr again (may be need for some other catch)
return Promise.reject(error);
});
Run Code Online (Sandbox Code Playgroud) 我正在使用 redux saga 和 React router v6,我想从我的一个 saga 重定向到路由,有办法做到这一点吗?