I am attempting to use array.push within a for loop in my TypeScript code:
var rows = [
{
id: '1',
category: 'Snow',
value: 'Jon',
cheapSource: '35',
cheapPrice: '35',
amazonSource: '233'
}
];
var newRow = {
id: productName,
category: category,
value: _value.toString(),
cheapSource: merchantName,
cheapPrice: lowPrice,
amazonSource: suppData[k][2]
};
rows.push(...newRow);
export default function DataTable() {
const { user } = useUser();
return (
<div>
{user ? (
<div
style={{
height: 400,
width: '75%',
backgroundColor: 'white',
marginLeft: 'auto',
marginRight: 'auto',
marginTop: '50px',
marginBottom: '50px'
}}
>
<DataGrid
rows={rows}
columns={columns}
pageSize={5}
rowsPerPageOptions={[5]}
checkboxSelection
onRowClick={get5CatDataNoStockCheck}
/>
</div>
) : (
<div>
<SignIn />
</div>
)}
</div>
);
}
The issue I'm encountering is that it consistently pushes the same row even if I change its value just before?
PS: A straightforward array.push is not feasible since the array is not "extendable"