我正在从后端获取一些数据,我需要将其连接到前端。它以对象数组的形式出现。我当前的代码仅返回数组中的最后一个对象:
// @flow
import AnyAction from "redux";
import { ActionTypes } from "./../constants";
import type { Block } from "./types";
const initialState = {
fetching: false,
blocks: []
};
const someReduceFunction = () => {};
export default function Blocks(state: Block[] = initialState, action: AnyAction): Block[] {
switch (action.type) {
case ActionTypes.GET_BLOCKS_REQUEST:
return state;
case ActionTypes.GET_BLOCKS_SUCCESS:
console.log(action.res);
console.log(Object.assign({}, state.blocks, ...Object.values(action.res)));
return Object.assign({}, state.blocks, ...Object.values(action.res));
case ActionTypes.GET_BLOCKS_FAILURE:
return state;
default:
return state;
}
}