简体   繁体   English

TypeError:无法添加属性 0,object 不可扩展

[英]TypeError: Cannot add property 0, object is not extensible

how to solve this problem?如何解决这个问题呢? I'm retrieving data from firestore database.我正在从 firestore 数据库中检索数据。

TypeError: Cannot add property 0, object is not extensible TypeError:无法添加属性 0,object 不可扩展

Below is my code pushing the data to my events array but encountered this error:以下是将数据推送到我的事件数组但遇到此错误的代码:

 let events: any = [];

  const q = query(collection(DB, `events/${userType}/${uid}`));
  onSnapshot(q, (querySnapshot) => {
    querySnapshot.forEach((doc) => {
      events.push({ ...doc.data() });
    });
  });
  return events;

Declare your events array and handle your return functionality within the onSnapshot method.在 onSnapshot 方法中声明您的事件数组并处理您的返回功能。

const q = query(collection(DB, `events/${userType}/${uid}`));
onSnapshot(q, (querySnapshot) => {
 let events: any = [];
 querySnapshot.forEach((doc) => {
   events.push({ ...doc.data() });
 });
 setEventsState(events)
});
return;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React App-TypeError:无法添加属性setState,对象不可扩展 - React App - TypeError: Cannot add property setState, object is not extensible 材料表类型错误:无法添加属性表数据,对象不可扩展 - Material-table TypeError: Cannot add property tableData, object is not extensible Jest TestEnvironment - 类型错误:接下来无法添加属性,object 不可扩展 - Jest TestEnvironment - TypeError: Cannot add property next, object is not extensible 未捕获的类型错误:无法添加属性 0,object 在 Array.push 不可扩展 - Uncaught TypeError: Cannot add property 0, object is not extensible at Array.push React:无法添加属性“X”,对象不可扩展 - React : cannot add property 'X', object is not extensible 无法添加属性“X”,对象不可扩展 angular 9 - Cannot add property "X", object is not extensible angular 9 未捕获的TypeError:无法添加属性12,对象不可扩展 - Uncaught TypeError: Can't add property 12, object is not extensible React Error(TypeError):无法添加属性上下文,对象不可扩展 - React Error (TypeError): Can't add property context, object is not extensible 为什么我在 redux-slice 中收到错误消息“Uncaught (in promise) TypeError: Cannot add property bookId, object is not extensible”? - Why I am getting an error as "Uncaught (in promise) TypeError: Cannot add property bookId, object is not extensible" into my redux-slice? 无法添加属性,在 React 组件中绑定 props 时对象不可扩展 - Cannot add property, object is not extensible when binding props in React component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM