Część kodu, w którym mam problem jest:Wystąpił błąd wewnętrzny w React wydajności kodu pomiaru
constructor(props){
super(props);
this.state = {
allcars: null,
minValue: 0,
maxValue: 50000,
step: 1000,
firstValue: null,
secondValue: null,
chcboxValue: false,
chcboxManualValue: false,
chcboxAutomaticValue: false
};
this.handleFilterChange = this.handleFilterChange.bind(this);
this.handlePriceUpdating = this.handlePriceUpdating.bind(this);
this.updateCarsToShow = this.updateCarsToShow.bind(this);
this.handleTransmissionUpdating = this.handleTransmissionUpdating.bind(this);
this.resetPriceFilter = this.resetPriceFilter.bind(this);
this.resetTransimissionFilter = this.resetTransimissionFilter.bind(this);
}
componentWillMount(){
this.setState({firstValue: this.state.minValue, secondValue: this.state.maxValue, allcars: this.props.carsToShow});
}
componentWillReceiveProps(nextProps) {
//We get the filter which is removed
let isRemoved = this.props.filters.filter(i => {
return nextProps.filters.filter(a => {
return i.searchFilter[0] !== a.searchFilter[0];
});
});
//If something is removed
if(isRemoved.length > 0){
let removedFilter = isRemoved[0].searchFilter[0]; //The name of removed filter
switch (removedFilter){
case "price":
this.resetPriceFilter();
break;
case "transmission":
this.resetTransimissionFilter();
break;
default:
console.log("Nothing");
}
}
}
resetPriceFilter(){
this.setState({firstValue: this.state.minValue, secondValue: this.state.maxValue, chcboxValue: false});
//We update the cars list in the store
this.updateCarsToShow(this.state.allcars);
}
resetTransimissionFilter(){
this.setState({chcboxManualValue: false, chcboxAutomaticValue: false});
}
Jeśli removedFilter
ma wartość „transmisji” w componentWillRecieveProps mam dwa ostrzeżenia:
bundle.js:8335 Warning: There is an internal error in the React performance measurement code. Did not expect componentDidUpdate timer to start while componentWillReceiveProps timer is still in progress for another instance.
bundle.js:71248 Uncaught TypeError: Cannot read property 'top' of undefined
A także jeśli state
nie został zaktualizowany Jeśli removedFilter
ma wartość "transmission"
. Jeśli konsola loguje coś wewnątrz tego przypadku, jest pokazywana, więc znajduje się w tym przypadku, ale z jakiegoś powodu stan nie jest aktualizowany.
Jeśli removedFilter
ma wartość "price"
, to wszystko działa tak, jak powinno. Numer state
został zaktualizowany i nie otrzymuję żadnych ostrzeżeń.
spróbuj usunąć hook 'componentWillMount', możesz ustawić te stany w konstruktorze. – xiaofan2406
Czy możesz zduplikować błąd w CodePen lub jsFiddle? Próbowałem, ale myślę, że tracę część twojej logiki, ponieważ nie mogłem replikować. –