jeffersonRibeiro / react-shopping-cart

🛍️ Simple ecommerce cart application built with Typescript and React

Home Page:https://react-shopping-cart-67954.firebaseapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get confused inside componentWillReceiveProps

KaiyaoZhang opened this issue · comments

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!

@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