当我调度getUser操作生成器时。我的代码有问题吗?
//ACTION
export const getUser = (uid) => dispatch =>{
console.log('hellow from getuser');
return axios
.get(`url/${uid}`)
.then((res) =>{
const userData = res.data;
console.log(userData);
dispatch({
type: USER_DETAILS,
userData
});
}
)
};
//REDUCER
const userReducerDefaultState = [];
const userReducer = (state = userReducerDefaultState,
action) =>{
console.log(action.userData); //*1
switch(action.type){
case 'USER_DETAILS':{
console.log('hi'+{...action.userData}); //*2
return[
...state,
action.userData
]
}
当我调度getUser时,我从* 2 console.log获得了“ Hi [object object]”。 但是从* 1 Console.log获得了以下数据。这也是来自* 2的所需数据。
bio:null
followers:[]
followings:[]
name:"saheb"
posts:(5) [{…}, {…}, {…}, {…}, {…}]
__v:0
_id:"y08RxtsHeacQTwiuNTAA"
答案 0 :(得分:1)
你可以做到
console.log('hi',{...action.userData})