Step 1 : Package installation
https://redux-toolkit.js.org/introduction/getting-started
npm install @reduxjs/toolkit
npm install react-redux
Step 2 : Configuring store & creating a profile slice
https://redux-toolkit.js.org/tutorials/quick-start
https://redux-toolkit.js.org/tutorials/quick-start#create-a-redux-store
https://redux-toolkit.js.org/tutorials/quick-start#provide-the-redux-store-to-react
https://redux-toolkit.js.org/tutorials/quick-start#create-a-redux-state-slice
Step 3 : call profile slice action using dispatch hook from login
Step 4 : use data update in the store from home screen using useSelector hook
Hooks.ts
import {TypedUseSelectorHook, useDispatch, useSelector} from 'react-redux';
import type {AppDispatch, RootState} from './index';
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
Store.ts
import {
configureStore,
combineReducers,
CombinedState,
AnyAction,
} from '@reduxjs/toolkit';
import ProfileSlice from './slice/ProfileSlice';
const combinedReducer = combineReducers({
profile: ProfileSlice,
});
const rootReducer = (state: CombinedState<any>, action: AnyAction) => {
if (action.type === 'RESET') {
state = undefined;
}
return combinedReducer(state, action);
};
export const store = configureStore({
reducer: rootReducer,
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;