mobx Error 'Reaction[observerobserved] 是什么问题?
what is the issue mobx Error 'Reaction[observerobserved]?
请帮我解决这个问题:
我正在使用 mobx-state-tree + React + mobx + Socket.io ,我正在为项目编写聊天,并用于连接 socket.io
我从服务器获取聊天列表,然后使用操作将他放入 mobx-state-tree 存储,然后我想从 mobx-state-tree 存储获取数据并使用 map 函数渲染元素
但是,我发现了两个错误
这是我用于聊天的 mobx-state-tree 模型
enter image description here
这是我尝试映射数据的代码
enter image description here
这是问题
enter image description here
但是错误“user”undefined 非常奇怪,因为当我使用 console.log() 显示数据时,数组有这个数据并显示在控制台
好的,我发现 Reaction[observerobserved] 有问题,这是因为呈现聊天列表的组件没有包装到观察者函数中
但是当我对他调用 map 方法时,我仍然遇到未定义数组属性的问题
解决 |Reaction[observerobserved]”
需要将组件包装到 observer() 函数中以订阅更改
对于第二个问题,使用未定义的属性:
屏幕上的第一个解决方案是错误的,因为在这种情况下你尝试获取未定义的索引'item.chat_users[index]”,解决方案是使用 map for chat_users array to,然后渲染内部项目对于此数据“item.chat_users.map(....)”
请帮我解决这个问题: 我正在使用 mobx-state-tree + React + mobx + Socket.io ,我正在为项目编写聊天,并用于连接 socket.io 我从服务器获取聊天列表,然后使用操作将他放入 mobx-state-tree 存储,然后我想从 mobx-state-tree 存储获取数据并使用 map 函数渲染元素 但是,我发现了两个错误 这是我用于聊天的 mobx-state-tree 模型 enter image description here
这是我尝试映射数据的代码 enter image description here
这是问题
enter image description here
但是错误“user”undefined 非常奇怪,因为当我使用 console.log() 显示数据时,数组有这个数据并显示在控制台
好的,我发现 Reaction[observerobserved] 有问题,这是因为呈现聊天列表的组件没有包装到观察者函数中
但是当我对他调用 map 方法时,我仍然遇到未定义数组属性的问题
解决 |Reaction[observerobserved]” 需要将组件包装到 observer() 函数中以订阅更改
对于第二个问题,使用未定义的属性:
屏幕上的第一个解决方案是错误的,因为在这种情况下你尝试获取未定义的索引'item.chat_users[index]”,解决方案是使用 map for chat_users array to,然后渲染内部项目对于此数据“item.chat_users.map(....)”