gpt4 book ai didi

react-native - react 原生 mobx 值不是原始值

转载 作者:行者123 更新时间:2023-12-04 04:53:33 25 4
gpt4 key购买 nike

我构建了 native 应用程序,并且正在使用 mobx。
进入商店,我有一个名为工具的数组,当我尝试将值分配到数组时,我得到了数组

Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[Reaction@1] Error: [serializr] this value is not primitive: 14


 class Task {
@persist @observable id = ''
@persist @observable title = ''
@persist @observable description = ''
@persist @observable tools = []

constructor(id,title,description,tools){
console.log('new task')
console.log(id,title,description,tools)
this.id = id
// this.title = title
this.description = description
this.tools = tools;

}

TasksStore - 在这里我创建了 Task 的新对象。
    import { observable, action, computed } from 'mobx'
import { persist } from 'mobx-persist'
import Task from '../Task/Task'
class TasksStore {

@persist('list',Task) @observable tasks = []
@observable storeHydrated = false;


@action done(){
this.storeHydrated = true

}

@action addNewTask(task){
this.tasks.push(new Task(0,task.title,task.description,task.tools))
console.log('tasks is',this.tasks)
}






}


const taskStore = new TasksStore();
export default taskStore;

当我删除
    @persist @observable tools = []

该应用程序运行良好。

最佳答案

@persist('list') @observable tools = [] 

尝试设置工具类型。
它会工作

关于react-native - react 原生 mobx 值不是原始值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49711437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com