I am working in React Native and sending payloads to my redux store: accessToken and firebase_userId after they have been retrieved.
They are sent using dispatch() in an useEffect() function.
When I log the state of my redux store though only the accessToken is being sent to the store and not the firebase_userId.
How can I dispatch both payloads at once from my component so they both are sent to my redux store?
Order of Operations:
User Log in --> retreives accessToken and firebase_userId --> state is set to both of these values --> useEffect() executes dispatching accessToken and firebase_userId to the redux store.
COMPONENT DISPATCHING accessToken and firebase_userId
const [accessToken, setAccessToken] = useState("");
const [firebase_userId, setFirebase_userId] = useState("");
const dispatch = useDispatch();
//listens for state of accessToken and firebase_userId to be set
useEffect(() => {
dispatch({
type: "access_token",
payload: accessToken
});
}, [accessToken]);
useEffect(() => {
dispatch({
type: "firebase_userId",
payload: firebase_userId,
});
}, [firebase_userId]);
function onSignIn(){
...//Signs in to firebase and returns accessToken and firebase_userId
//set the state of the component with retrieved values
setAccessToken(googleUser.accessToken);
setFirebase_userId(result.user.uid);
}
REDUX STORE
import React from "react";
import symbolicateStackTrace from "react-native/Libraries/Core/Devtools/symbolicateStackTrace";
import { applyMiddleware, createStore } from "redux";
import thunk from "redux-thunk";
const initialState = {
access_token: "",
firebase_userId: "",
};
const counterReducer = (
state = initialState,
if (action.type === "access_token") {
return {
...state,
access_token: action.payload,
};
}
if (action.type === "firebase_userId") {
return {
...state,
firebase_userId: action.payload,
};
}
return state;
};
const store = createStore(counterReducer, applyMiddleware(thunk));
export default store;