最近我发现我的 React 应用程序存在一些性能问题,经过一些研究我发现了 React Memo。一些训练示例作为例外工作,但是当将其连接到我的应用程序时,它没有任何效果。我发现问题出在 useLocation 上。
const Table = React.memo(() => {
const location = useLocation();
return <div>something</div>
},(prevProps, nextProps) => {
return true //I dont want re-render this Component when parent component is re-rendered
})
没有 useLocation 它可以工作,但我需要这个位置,因为基于这个位置,更具体地说,基于来自这个位置的过滤器,我调用 API 数据。就像是
const location = useLocation();
useEffect(() => {
dispatch(getData(location.search))
}, [location]);
有更好的解决方案或一些提示吗?