Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Arrays reactjs将导入的JSON对象导入数组列表_Arrays_Json_Reactjs_Arraylist - Fatal编程技术网

Arrays reactjs将导入的JSON对象导入数组列表

Arrays reactjs将导入的JSON对象导入数组列表,arrays,json,reactjs,arraylist,Arrays,Json,Reactjs,Arraylist,我可以显示通过redux获得的JSON对象。 但返回时,列表为空。 如何将发送到列表中的JSON对象作为 有效载荷: 返回{ 类型:用户信息, 有效载荷:{ 简介:名单 }, } 如何使用Redux处理异步请求 我将对用户信息操作可能具有的每种状态类型进行操作。例如,用户信息请求有三种状态:默认、已加载和失败 constuserinforequest=()=>{type:USER\u INFO\u REQUEST}; const userInfoLoaded=(userInfo)=>{type:

我可以显示通过redux获得的JSON对象。 但返回时,列表为空。 如何将发送到列表中的JSON对象作为

有效载荷: 返回{ 类型:用户信息, 有效载荷:{ 简介:名单 }, }


如何使用Redux处理异步请求

我将对用户信息操作可能具有的每种状态类型进行操作。例如,用户信息请求有三种状态:默认、已加载和失败

constuserinforequest=()=>{type:USER\u INFO\u REQUEST};
const userInfoLoaded=(userInfo)=>{type:USER\u INFO\u LOADED,userInfo};
const userInfoFailed=(error)=>{type:USER\u INFO\u FAILED,error};
您需要将
userInfo
操作转换为thunk,以便该操作属性可以在操作创建者内处理其内部异步状态

constuserinforequest=()=>(dispatch,getState)=>{
分派(userInfoRequest());
获取(…)
.then(response=>response.json())
.then(结果=>dispatch(userInfoLoaded(结果))
.catch(error=>dispatch(userInfoError(error))
}

如何使用Redux处理异步请求

我将对用户信息操作可能具有的每种状态进行操作。例如,用户信息请求有三种状态:默认、已加载和失败

constuserinforequest=()=>{type:USER\u INFO\u REQUEST};
const userInfoLoaded=(userInfo)=>{type:USER\u INFO\u LOADED,userInfo};
const userInfoFailed=(error)=>{type:USER\u INFO\u FAILED,error};
您需要将
userInfo
操作转换为thunk,以便该操作属性可以在操作创建者内处理其内部异步状态

constuserinforequest=()=>(dispatch,getState)=>{
分派(userInfoRequest());
获取(…)
.then(response=>response.json())
.then(结果=>dispatch(userInfoLoaded(结果))
.catch(error=>dispatch(userInfoError(error))
}

API调用是一种异步代码,函数在获得响应之前返回请先了解JS中异步编程的工作原理。API调用是一种异步代码,函数在获得响应之前返回请先了解JS中异步编程的工作原理。
export const USER_INFO = 'USER_INFO';

let list = [];

export function userAction(newValue) {

fetch("http://127.0.0.1:8000/api/account/me", {
    headers: {
        Authorization: `Bearer ${localStorage.getItem("id_token")}`,
        "Content-Type": "application/json"
    }
})
    .then((response) => response.json() )
    .then((responseData) =>{
        list = JSON.stringify(responseData);
        console.log(list);
       // console.log(JSON.parse(liste));
        return list;
    });

**//list appears empty when I check here**
**console.log(list);**

return {
    type: USER_INFO,
    payload: {
        profile: list
    },
}
}