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

114
Visualizações
How to get custom Arg in configureStore reducer?

I would like to give additional parameters for Dependency Injection to Reducer.

When I created the Store, I added Arguments like this.

export default configureStore({
  reducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      thunk: { extraArgument: { service } },
    }).concat(logger),
  devTools: true,
});

I know how to use it in createAsyncThunk function, but I don't know how to use it in other Reducer. There is no third parameter.

In the following case, there is no third factor.

const authSlice = createSlice({
  name: 'auth',
  initialState,
  reducers: {
    logout: (state, action, third) => {

      // third is undefiend!!! it doesn't get value.
      // but createAsyncThunk does

      const { extra} = third;
      const { service } = extra;
      service.authService.logout();
      return {
        isLoggedIn: false,
        userId: null,
        profile: {
          name: null,
        },
        token: null,
      };
    }
  },
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Something like your service.authService.logout(); is a side effect and side effects are never allowed in a Redux reducer. A reducer is only allowed to read state and action and (in the case of createSlice) modify state. No other side effects are allowed. So nothing like this will be available in your reducers.

You could be using the listener middleware for this though.

listenerMiddleware.startListening({
  actionCreator: authSlice.actions.logout,
  effect: async (action, listenerApi) => {
    listenerApi.extra.authService.logout()
  },
})
about 4 years ago · Juan Pablo Isaza Relatório
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