Answer the question
In order to leave comments, you need to log in
Why is the component not being rerendered?
Let's say we have a collection of objects.
const mainData = {
1: {
title: 'подушка',
price: 500
},
2: {
title: 'матрешка',
price: 520
},
3: {
title: 'игрушка',
price: 520
}
sort(data){
let suitableData = Object.values(data).sort((a,b) => a.price > b.price ? -1 : 1)
return suitableData
}
let data;
data = mainData
// когда меняю состояние то применяю сортировку (создаю новую коллекцию)
if(this.props.on ){
data = this.sort(mainData)
}
{
Object.keys(data).map( (elem, i ) => {
return <Item key={i} data={data[elem]} partners={partners} />
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question