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

235
Visualizações
slice reducer for key "pageName" returned undefined during initialization

I am creating redux app using createSlice(), but get the error:

Error: The slice reducer for key "pageName" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.

Here is the minimal example for this error.

pageNameSlice.js:

import { createSlice } from "@reduxjs/toolkit";

const pageNameSlice = createSlice({
    name: 'pageName',
    initalState: "",
    // The `reducers` field lets us define reducers and generate associated actions
    reducers: {
      setPageName: (state, newName) => {
          state.pageName = newName
      }
    }
});

export default pageNameSlice.reducer;

store.js:

import { configureStore } from '@reduxjs/toolkit';
import pageNameReducer from '../features/pageNameSlice';

export const store = configureStore({
  reducer: {
    pageName: pageNameReducer
  },
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have a typo there - initalState should be initialState. (This is more common than you might think ^^)

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