【发布时间】:2022-01-24 04:30:47
【问题描述】:
在我的 React 应用程序中,我的一个常用功能组件中有以下代码。所以基本上,在每次路由更改时,我都会检查用户是否可以访问该页面(这种全局逻辑)
let history = useHistory();
props.history.listen((location, action) => {
checkIfUserHasAccessToPage();
});
但是,使用此代码,我观察到后续页面导航(即用户在同一会话中时)的 UI 缓慢和滞后。
我可以使用任何替代方法来避免性能问题吗?
【问题讨论】:
标签: reactjs react-hooks react-router