I'm trying to display a table in react-native but it requires the data to be in arrays,
the API returns an object with all the rows, so far I have managed to convert only if there is a single row and doesn't convert the second row if its available.
Api from the server
0: {title: "Transportation", amount: "100"}
1: {title: "Food", amount: "50"}
what I need is
0:["Transportation", "100"]
1:["Food", "50"]
this is my code
const state = this.state;
let table = this.state.payments;
console.log(table);
const tableD = Object.keys(table[0]).map((key, index) => table[0][key]);
console.log(tableD);
const tableData = [tableD];
console.log(tableData);
return (
<Table borderStyle={{borderWidth: 2, borderColor: theme.colors.primary}}>
<Row data={state.tableHead} style={{ height: 40, backgroundColor: theme.colors.gray2}} textStyle={{margin: 6}}/>
<Rows data={tableData} textStyle={{ margin: 6, }}/>
</Table>
)
this is the error that I get
Invariant Violation: Objects are not valid as a React child (found: object with keys {title, amount}). If you meant to render a collection of children, use an array instead.
What could I be doing wrong?