Get confused inside componentWillReceiveProps
KaiyaoZhang opened this issue · 1 comments
KaiyaoZhang commented
componentWillReceiveProps(nextProps) {
const { filters: nextFilters, sort: nextSort } = nextProps;
const { filters } = this.props;
if (nextFilters.length !== filters.length) {
this.handleFetchProducts(nextFilters, undefined);
}
if (nextSort !== this.props.sort) {
this.handleFetchProducts(undefined, nextSort);
}
}
Hi, inside componentWillReceiveProps, I am confused how does the coming props nextFilter and nextSort get stored in filters and sort each time, and what does this command line mean here: const { filters : nextFilters, sort: nextSort } = nextProps;
Thank you!
JaymesKat commented
@KaiyaoZhang The filters and sort prop values are being destructured and being renamed in the statement you pointed out. You can see the explanation for Object destructuring here