Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

505
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!