I had an action make an api call to a backend to retrive an array of objects. The action then dispatches an update to a state variable. At this point I meet the following error:
Objects are not valid as a React child (found: object with keys {x, y}).
If you meant to render a collection of children, use an array instead.
The following code has been minimized to still produce the error:
getDonationData : (reportType, recordCount) => (dispatch => {
return Axios.post(`http://localhost:4000/reports/`,
{
reportType, recordCount
}
)
.then(apiResponse => {
const returnedArray = apiResponse.data;
dispatch({
type : 'reportData',
payload : [{x: 1, y: 2}, {x: 4, y: 3}]
})
})
})
If the objects in the array are replaced by numbers like [1, 2, 3] the error goes away.
Does anyone know why this is happening and how to work around the possible nesting limitation? My actual data has about 500 items and the x values are also date objects (this is chart data).
Reducer code:
case 'reportData':
return {
...previousState,
reportData : action.payload
};