I am sorting array in 'onChange' method and setting it up with 'setState' but after that it's rendered unsorted;
I've update function
// this method is called as a callback from component (on component change)
async onSomeComponentUpdate(data) {
let newData = [];
// ... some sorting fctions
console.log(newData); // it's sorted here
this.setState(state=> ({data: newData}));
}
After that I'm logging the render fction
render() {
// data are still sorted here
Object.keys(this.state.data).map((key) => {
console.log(this.state.data[key]);
});
// but down here it is not sorted
return (
{Object.keys(this.state.data).map((key) => {
return (this.SomeComponentRow(key,this.state.data[key]))
})}
);
}
and the component function with binded onUpdate
SomeComponentRow(key, item) {
return <SomeComponent key={key} item={item} onUpdate={this.onSomeComponentUpdate} />;
}