I am working in react redux. I stored the value in reducer and try to retrieve it. Value is undefined? I am getting the sessionId from url. In App.js, sessionId is having value.
http://localhost:3000?SessionId=89e2ff80-c1d7
import * as types from '../lib/store/action';
const App = () => {
const dispatch = useDispatch();
useEffect(function () {
const params = new URLSearchParams(window.location.search);
const SessionId = params.get('SessionId');
if (SessionId != null && SessionId.length) {
console.log("saving SessionId: " + SessionId);
dispatch(
types.updateData({
SessionId: SessionId
})
);
}
})
}
Reducer.js
import * as types from './action';
export const initialState = {
recDetails: {
name: '',
country: '',
city: ''
},
SessionId: ''
}
const Datareducer = (state = initialState, action) => {
switch (action.type) {
case types.UPDATE__DATA:
const output = action.payload;
if (output.recDetails) {
state.recDetails = output.recDetails;
}
if (output.SessionId) {
state.SessionId = output.SessionId;
}
return {
...state,
}
break;
default:
return state;
}
}
export default Datareducer;
Component1.js
import * as types from '../../lib/store/action';
const { SessionId } = useSelector(state => state.app.DataReducer.SessionId);
const uDispatch = useDispatch();
useEffect(() => {
alert(SessionId);}
SessionId is undefined.....
http://localhost:3000?SessionId=89e2ff80-c1d7
Hi, I am reading the sessionId from ur paraameter in app.js. SessionId is showing in app.js and then store in reducer. Readming sessionId in component1 is undefined.