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

118
Views
Why do I have to access my Redux state like "state.topicsReducer.topics"?

I've successfully created a redux store using createSlice from @reduxjs/toolkit as follows:

const initialState = {
    topics: {
        '123': {
            id: '123',
            name: 'example topic',
            icon: 'icon url',
            quizIds: ['456']
          }
    }
}

const options = {
    name: 'topics',
    initialState: initialState,
    reducers: {
        addTopic: (state, action) => {
            return {
                ...state,
                topics: {
                    ...state.topics,
                    [action.payload.id]: action.payload
                }
            }
        }
    }
}

When creating a selector I found that I have to do the following:

export const selectTopics = state => state.topicsReducer.topics;

Why do I need the "topicsReducer"? In my course I've always seen state accessed like 'state.topics'. Did I mess something up in my options variable?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Make sure you pass the reducers object to combineReducers(reducers) or configureStore like this:

combineReducers({ topics: topicsReducer });

// or

configureStore({ reducer: { topics: topicsReducer } })

The state shape will be { topics }. Then you can create selector like:

export const selectTopics = state => state.topics;
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!