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

506
Visualizações
UseSelector returns undefined even the state is updated correctly

I have a react admin project using React Redux.

Below is the detail:

slice.tsx:

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

const newRevisionSlice = createSlice({
    name: 'newRevision',
    initialState: {
      dataList: [],
      status: 'idle'
    },
  reducers: {
    postSaveNewRevision: (state  = { dataList:[], status:"idle" }, action) => {
      return { ...state, dataList: action.payload, status: 'success' };

      }
    }
  });


export const { postSaveNewRevision } = newRevisionSlice.actions;
export default newRevisionSlice.reducer;
component.tsx: 

const newRevision  = useSelector((state: RootState) => state.newRevision)

store.tsx:

declare global {
  interface Window {
    __REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
  }
}

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const rootReducer = combineReducers({
  fleetType: fleetTypeApi,
  revisionNo: revisionNoApi,
  revisionDate:revisionDateApi,
  newRevision: newRevisionApi,
});

const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));

const useAppDispatch = () => store.dispatch;

export type RootState = ReturnType<typeof store.getState>;

export { useAppDispatch };

ReactDOM.render(
  <Provider store={store}>
    <React.StrictMode>
      <App />
    </React.StrictMode>
  </Provider>,
  document.getElementById('root')
);

In react redux devtool I see that the state is updated correctly when I dispatch. However, useSelector so newRevision in the component returns undefined.

Could you please help me?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Is there by any chance your newRevisionSlice and the newRevisionApi in store.jsx are 2 different reducers? If that is the case, then you have 2 separate stores for newRevision and they won't share states.

Similar issues that are resolved:

  • useSelector not updating with Redux Toolkit
  • useSelector state returns undefined

Additionally, because your useSelector() return undefined it could also be the case that there is a typo somewhere with the names of slices / reducers.

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