@ejdelmonico above solution not work but after i remove {} from object assign it return value as i expected
const newState = Object.assign(...state, action.payload.data);
this result like json from my api
[{
"id":7,
"name":"Smart Phone",
"count_product":25,
"product":{
"id":125,
"name": " V5",
"image":"v5_01-06-2018-1515204450.jpg",
"price":"55.00"
}
},
{etc.....}
]
if i add {} back
const newState = Object.assign({}, ...state, action.payload.data);
this result like this
{
0:{
"id":7,
"name":"Smart Phone",
"count_product":25,
"product":{
"id":125,
"name": " V5",
"image":"v5_01-06-2018-1515204450.jpg",
"price":"55.00"
}
},
{etc.....}
}
is this a right solution to remove {} from object assign or ... ?
and another solution is add action.payload.data as object bcoz my data from laravel has remove wrapper
const ProductReducer = (state = {data:[]}, action) => {....});
const newState = Object.assign({}, state, {data: action.payload.data});
-
which is good way ?
-
does i shouldn't use Resource::withoutWrapper(); ?
must let it wrap by data for best practice ?
{
data: [
{id: 1, .....}m
etc......
]
}
so i don't need to make action.payload.data as {data: action.payload.data} ?