I have a response from the API like this, https://codebeautify.org/jsonviewer/cbbfa709
why in react table v6 there is an error like this " Error: Objects are not valid as a React child (found: object with keys {branchStock, product, lastOrder, productFocusId, qtySuggestion, orderQuantity}). If you meant to render a collection of " ?
even though the accessor name is in accordance with the object properties, how to solve this problem?
"react-table-v6": "^6.8.6"
this is my state
const [state, setState] = useState({
isLoading: true,
tab: 'tab-1',
productFocus: []
})
success function to set state
success => {
const { data: { items } } = success.data
setState(prevState => {
return {
...prevState,
productFocus: items.map((list) => {
return Object.assign({}, {
branchStock: list.branchStock,
product: list.product,
lastOrder: list.lastOrder,
productFocusId: list.productFocusId,
qtySuggestion: list.qtySuggestion,
orderQuantity: 0
})
}),
isLoading: false
}
})
},
this is my table component
{state.tab === "tab-1" ?
<>
<div className="my-5">
{state.isLoading ? (<p>loading ...</p>) : (
<Table
data={state.productFocus}
type='productFocus'
dataListLength={10}
showPagination={false}
/>
)}
</>
}
this is my cell
productFocus: [
{
Header: 'JKN',
accessor: '',
sortable: false,
headerStyle,
className: 'column-odd',
},
{
Header: 'Product Name',
accessor: 'product.productName',
sortable: false,
headerStyle,
className: 'column-odd',
Cell: ({ row, original }) => {
console.log('ori', original)
return <p>tes</p>
}
},
{
Header: 'Price',
accessor: 'product.hnaPrice',
sortable: false,
headerStyle,
className: 'column-odd',
},
{
Header: 'Promo',
accessor: '',
sortable: false,
headerStyle,
className: 'column-odd',
},
{
Header: 'Branch Stock',
accessor: 'branchStock',
sortable: false,
headerStyle,
className: 'column-odd',
},
{
Header: 'Quantity Suggestion',
accessor: 'qtySuggestion',
sortable: false,
headerStyle,
className: 'column-odd',
},
{
Header: 'Order Quantity',
accessor: '',
sortable: false,
headerStyle,
className: 'column-odd',
},
{
Header: 'SubTotal',
accessor: '',
sortable: false,
headerStyle,
className: 'column-odd',
},
]
on other pages the table works well with different data according to the response from the API
<Table
data={state.lastSummaryByOutlet.collection}
type='infoPaidCollection'
dataListLength={10}
showPagination={false}
/>
infoPaidCollection: [
{
Header: 'No Invoice',
accessor: 'invoiceNo',
sortable: false,
headerStyle,
className: 'column-event'
},
{
Header: 'Amount',
accessor: 'amount',
sortable: false,
headerStyle,
className: 'column-odd',
Cell: ({ original }) => `Rp ${toCurrency(original.amount)}`
}
],