we have a single store now, it mean if we can get back our store, then we can do store.dispatch or store.subscribe operations. but how to get store in our component? Go to App.js, make our IndexRouter in the Provider section.
Our SideMenu and TopHeader will use the store. so go to TopHeader first, because Topheader is publish the state.Its response is Dispatch the state to store. In TopHeader, we use connect to make TopHeader as child components, we can get value from parameter of props.
functionTopHeader(props) { // NOTE: changed to redux, state is not neccessary. // const [collapsed, setCollapsed] = useState(false) ... const changeCollapsed = () => { // NOTE: changed to redux, state is not neccessary. // setCollapsed(!collapsed); props.changeCollapsed(); } }
when user click the icon in TopHeader, the workflow go to store, and store find out the CollapsedReducer, then excute the logic to change to new state. below are the CollapsedReducer.js content:
Back to SideMedu, SideMenu retrieve the state to collapse or expand himself. We also connectSideMenu first. It doesn’t need Dispatch anything, so our changing in SideMenu looks like:
// Add a request interceptor axios.interceptors.request.use(function (config) { // Do something before request is sent // Show Spin return config; }, function (error) { // Do something with request error // Hide Spin returnPromise.reject(error); });
// Add a response interceptor axios.interceptors.response.use(function (response) { // Any status code that lie within the range of 2xx cause this function to trigger // Do something with response data // Hide Spin return response; }, function (error) { // Any status codes that falls outside the range of 2xx cause this function to trigger // Do something with response error // Hide Spin returnPromise.reject(error); });