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

264
Views
React-redux Useselector no funciona. No se pueden leer las propiedades de Undefined ('channelId')

Estoy creando una aplicación React y usando Reduxjs Toolkit para la gestión del estado. No puedo entender por qué ChannelID y Channelname no están definidos aquí. Aquí está la aplicación.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

Aquí está la aplicaciónSlice

 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;

Mensaje de error ingrese la descripción de la imagen aquí

Código para tienda

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

0

Use configureStore para crear su tienda, esta es "una abstracción amigable sobre la función estándar de Redux createStore que agrega buenos valores predeterminados a la configuración de la tienda para una mejor experiencia de desarrollo". citado del documento rtk.

Para tu caso será como tal

 import appReducer from './%%WhereYourSliceResides import { configureStore } from '@reduxjs/toolkit' export const store = configureStore({ reducer: { app: appReducer, }, })

Luego, el selector recogerá state.app de su tienda.

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