Closed matinrco closed 2 years ago
Hi! the problem is that Navigate has IMHO a bug here https://github.com/remix-run/react-router/blob/main/packages/react-router/lib/components.tsx#L95. not having [] for running only once.
dispatch a new location make re-render components subscribed to, and the loop is generated because Navigate runs effects every render.
So you have 2 options 1) read the location from redux and use a NavigateFixed component https://codesandbox.io/s/redux-first-history-test-forked-pguxh1?file=/src/PrivateRoute.tsx
2) read location from useLocation (that has a copy stored on context) and is not subscribed to redux.
So you have 2 options
read the location from redux and use a NavigateFixed component https://codesandbox.io/s/redux-first-history-test-forked-pguxh1?file=/src/PrivateRoute.tsx
read location from useLocation (that has a copy stored on context) and is not subscribed to redux.
I fixed that by applying a convention for myself:
redux-first-history
actions for any out of component navigation (in slice/thunks ..)
and don't mix this usage xdso basically it's your second workaround 👍
@matinrco fixed here https://github.com/salvoravida/redux-first-history/issues/88
hey! thanks for your great work.
here is sandbox