Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda