Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在状态中检测到不可序列化的值_Reactjs_Redux_React Redux_Redux Toolkit - Fatal编程技术网

Reactjs 在状态中检测到不可序列化的值

Reactjs 在状态中检测到不可序列化的值,reactjs,redux,react-redux,redux-toolkit,Reactjs,Redux,React Redux,Redux Toolkit,我在登录并转到仪表板时看到此错误 它显示了这个错误 在以下路径的状态中检测到不可序列化的值:bugs.0。值:错误{name:“加载时崩溃”,详细信息:“3秒后崩溃”,步骤:“打开应用程序,它将崩溃”,优先级:1,分配:未定义,…} 看一看处理这个动作类型的减速器:bug/getbug 这是减速器: /* eslint-disable no-unused-vars */ import {createSlice} from '@reduxjs/toolkit' import {retrieveBu

我在登录并转到仪表板时看到此错误

它显示了这个错误 在以下路径的状态中检测到不可序列化的值:
bugs.0
。值:错误{name:“加载时崩溃”,详细信息:“3秒后崩溃”,步骤:“打开应用程序,它将崩溃”,优先级:1,分配:未定义,…} 看一看处理这个动作类型的减速器:bug/getbug

这是减速器:

/* eslint-disable no-unused-vars */
import {createSlice} from '@reduxjs/toolkit'
import {retrieveBugs} from '../bugController'

const slice = createSlice({
    name:"bug",
    initialState:[{}],
    reducers:{
        getBugs:(state) => retrieveBugs(),
        
        createBugs: (state,actions) =>{
            const {name,details,steps,priority,assaigned,creator,version,time} = actions.payload;
            state.LoggedIn =true;
            state.admin = true;
        },
        updateBug:(state,actions) => {
            const {name,details,steps,priority,assaigned,creator,version,time} = actions.payload;
            state.LoggedIn =true;
            state.admin= true;
        
        },
        markComplete:(state,actions) => {
            const {name,details,steps,priority,assaigned,creator,version,time} = actions.payload;
            state.LoggedIn =true;
            state.admin= true;
        }
    }
})

export default slice.reducer;

export const {getBugs, createBugs, updateBug, markComplete} = slice.actions;
这是bugController

import bugModel from '../Models/bugModel'

export function retrieveBugs(){
    let data = [];

    data.push(new bugModel({
        name:"Crash on load",
        details: "Crash after 3 seconds",
        steps: "Open application and it will Crash",
        assaigned: "Al Amzad",
        creator: "John Doe",
        priority: 1,
        version: "V1.0",
        time: "1:45",
    }))
    
      data.push(new bugModel({
        name:"Wont load",
        details: "Application doesn't load",
        steps: "Open the Application it won't Load ",
        assaigned: "Al Amzad",
        creator: "John Doe",
        priority: 3,
        version: "V3.0",
        time: "23:45",
    }))

    // eslint-disable-next-line no-unused-vars
    let sorted = data.sort((a,b) => {return a.priority - b.priority})

    return sorted;
}

一个新的bugModel将是一个类实例,因此不是一个简单的可序列化JS对象。所以,RTK特别注意到了这个错误,并警告您不要这样做

解决方法是切换到使用普通数据而不是类