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

167
Views
TypeError: Cannot read properties of undefined (reading 'roomId')

I'm trying to get the roomId from firestore but I'm stuck with this problem since last week I have tried different es6 syntax to overcome with but no result. Below I have provided the code it shows the error on selectRoomId

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

export const appSlice = createSlice({
  name: 'app',
  initialState: {
    roomId: null
  },
  reducers: {
    enterRoom: (state, action) => {
      state.roomId = action.payload.roomId;
    },
  },
});

export const { enterRoom } = appSlice.actions;
export const selectRoomId = state => state.app.roomId;
export default appSlice.reducer;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Spread your state and update the roomId only

reducers: {
  enterRoom: (state, action) => {
    ...state,
    roomId: action?.payload?.roomId;
  },
},
about 4 years ago · Juan Pablo Isaza Report

0

Console log to check what you get from the store object by changing the state to

export const state = (state) => state; 

this helped me, I was facing the same issue.

#Inside Component

const roomId = useSelector(state);
console.log(roomId);

#What I get from console

{user:{roomId: null}
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!