I have an API call, that is returning two objects: data and pageOutput.(我有一个API调用,它返回两个对象:data和pageOutput。)
{
data: "[{"title":["Travis Jackson HOF 1931 W517 # 12 - SGC 50"],"image":["https://i.ebayimg.com/00/s/MTYwMFg5NzY=/z/uU8AAOSwMtdd3ZXo/$_1.JPG"],"itemURL":["https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=2&toolid=10044&campid=5338164673&customid=vintagebaseball&lgeo=1&vectorid=229466&item=133253226463"]"
pageOutput: "{"pageNumber":["1"],"entriesPerPage":["100"],"totalPages":["2"],"totalEntries":["194"]}"
}
I have a reducer that is fetching the data from my API and storing data in aa state called 'baseball' like this.(我有一个reducer,它从我的API中获取数据并以这种状态(称为“棒球”)存储数据。) Note it is just storing the 'data' piece from my API call.(请注意,它只是存储来自我的API调用的“数据”片段。)
const baseballReducer = (state = [], action) => {
switch (action.type) {
case "INIT_BLOGS":
return action.data;
export const initializeBaseball = () => {
return async dispatch => {
const baseballCards = await baseballService.getAll();
dispatch({
type: "INIT_BLOGS",
data: JSON.parse(baseballCards.data)
});
};
};
I need to get the pageOutput into a separate state.(我需要将pageOutput设置为单独的状态。) Now i know that i could create a separate page reducer, make a call to the api and store that pageOutput data in a new state.(现在我知道我可以创建一个单独的页面精简器,调用api并将该pageOutput数据存储为新状态。) However, i think that it would be bad practice to make two different calls to the API?(但是,我认为对API进行两次不同的调用将是一种不好的做法?)
Is there a better way?(有没有更好的办法?) I was thinking of just storing all of the data (including the pageOutput) in the baseball state, but then I'm not sure if this is best practice or not, especially considering that I have a Pagination control that needs the updated active page to requery the database.(我本来只是想以棒球状态存储所有数据(包括pageOutput),但是然后我不确定这是否是最佳做法,尤其是考虑到我有一个分页控件需要更新的活动页面来重新查询数据库。) Hope this is clear enough--happy to provide any additional code.(希望这足够清楚-乐于提供任何其他代码。)
ask by John Rogerson translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…