I'm stuggling with my own ignorance... so please pardon me
But I can't get it right to add a row to an empty array (lets say the first time..)
This is my addRecord function ( after the 250th attempt to set state... :-( )
addRecord = () => {
let tsks = JSON.parse(JSON.stringify(this.state.tasks));
console.log('tsks=',tsks)
if (this.state.dropdownlistPLine === null || this.state.dropdownlistFinProd === null || this.state.dropdownlistSSchema === null) {
this.toggleDialog()
} else {
const newRecord = {
rowid: tsks.length+1,
ProdLine: this.state.dropdownlistPLine,
FinalProduct: this.state.dropdownlistFinProd,
sschema: this.state.dropdownlistSSchema,
StockonHand: 0,
StockonOrder: 0,
StockFree: 0,
TotKg: 0,
Weight: 0,
totpipes: 0,
actid: 0
};
console.log('New tasks', newRecord);
if (tsks.length > 0) {
this.setState({
tasks: [newRecord, ...tsks],
editID: newRecord.rowid
});
} else {
console.log('Adding first tasks', newRecord);
tsks.push(newRecord);
console.log('tsks = ', tsks);
this.setState({
tasks: this.state.tasks.concat(newRecord),
editID: newRecord.rowid
});
}
}
console.log('New tasks', this.state.tasks)
};
No matter what I tried to do, it just won't set the state... here's the console.log
tsks= []
New tasks {rowid: 1, ProdLine: "Mixer 1", FinalProduct: "MX-16422O", sschema: 4, StockonHand: 0, …}rowid: 1ProdLine: "Mixer 1"FinalProduct: "MX-16422O"sschema: 4StockonHand: 0StockonOrder: 0StockFree: 0TotKg: 0Weight: 0totpipes: 0actid: 0
Adding first tasks {rowid: 1, ProdLine: "Mixer 1", FinalProduct: "MX-16422O", sschema: 4, StockonHand: 0, …}rowid: 1ProdLine: "Mixer 1"FinalProduct: "MX-16422O"sschema: 4StockonHand: 0StockonOrder: 0StockFree: 0TotKg: 0Weight: 0totpipes: 0actid: 0__proto__: Object
tsks = [{…}]0: rowid: 1ProdLine: "Mixer 1"FinalProduct: "MX-16422O"sschema: 4StockonHand: 0StockonOrder: 0StockFree: 0TotKg: 0Weight: 0totpipes: 0actid: 0
New tasks []
Any help will be appreciated
Len