Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
In React Redux I am dispatching twice to the store in one component but only one payload is being delivered to the store

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;
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda