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

263
Visualizações
React-redux Useselector not Working. Cannot read properties of Undefined ('channelId')

I am Creating a React-app and using Reduxjs Toolkit for state management. I am not able to understand why ChannelID and Channelname are undefined here. Here is the App.js


import { useSelector } from 'react-redux'
import { selectChannelId, selectChannelname } from '../../reduxjs toolkit/appSlice'

const Chats = () => {

  const user = JSON.parse(localStorage.getItem("user"))
  const data = localStorage.getItem("userData");
  const [userData, setUserData] = useState(JSON.parse(localStorage.getItem("userData")))

  const ChannelId = useSelector(selectChannelId)       // Giving Error Here
  const channelName = useSelector(selectChannelname)   // Giving Error Here

Here is the appSlice

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

export const appSlice = createSlice({
    "name":'app',
    initialState:{
        channelId:null,
        channelName:null,
    },
    reducers:{
        setChannelInfo: (state,action)=>{
            state.channelId = action.payload.channelId
            state.channelName = action.payload.channelName
        },
    }
})

export const {setChannelInfo}= appSlice.actions

export const selectChannelId = (state) => state.app.channelId
export const selectChannelname = (state) => state.app.channelName

export default appSlice.reducer;

Error Message enter image description here

Code for Store

import { createStore } from "redux";
import reducers from "./reducers"

const store = createStore(reducers, {}, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())

 export default store;
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Use configureStore to create your store, this is "a friendly abstraction over the standard Redux createStore function that adds good defaults to the store setup for a better development experience." quoted from the rtk doc.

For your case it will be as such

import appReducer from './%%WhereYourSliceResides
import { configureStore } from '@reduxjs/toolkit'

export const store = configureStore({
reducer: {
  app: appReducer,
},
}) 

Then the selector will pick up state.app from your store.

about 4 years ago · Santiago Trujillo 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