-
redux-thunk react-router-dom v6개발/React 2022. 7. 11. 13:28
react router dom v6에서는 미들웨어 단에서 따로 처리하지 않아도 되고,
Router가 아니라 BrowserRouter로 앱을 감싸주면 됩니다.
그러고 나서 dispatch 할 때 useNavigate로 얻은 클로저를 같이 보내주면 됩니다.
applyMiddleware(ReduxThunk) ... <React.StrictMode> <Router> <Provider store={store}> <App /> </Provider> </Router> </React.StrictMode> ... return ( <> <button onClick={() => dispatch(goToHome(navigate))}>Go to home</button> <Post post={data} /> </> ); ... export const goToHome = (navigate) => (dispatch, getState) => { navigate('/'); };
'개발 > React' 카테고리의 다른 글
[Redux] 아주 아주 간단한 redux-saga 기본 (0) 2022.07.11 [Proxy error] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts[0] should be a non-empty string. (0) 2022.07.11 [Redux] 아주 아주 간단한 리덕스 기본 개념 3 (0) 2022.07.08 [Redux] 아주 아주 간단한 리덕스 기본 개념 2 (0) 2022.07.08 [Redux] 아주 아주 간단한 리덕스 기본 개념 (0) 2022.07.08