score:4

Accepted answer
componentWillReceiveProps(nextProps) {
  this.showCategory(nextProps);
}

showCategory(props) {
  let queryParam = props.params.category;
  // etc
}

score:1

componentWillReceiveProps(nextProps) {
 this.showCategory(nextProps);
}

componentWillMount(this.props){
 this.showCategory(this.props);
}

showCategory(props){
 const self = this;
 let queryParam = props.params.category;
 const availableCategories = props.categories;
 let matched = false;

 const count = availableCategories.length - 1;
 if(count === -1){
  this.setState({
    notFound: true
  });
 } else {
    filter(availableCategories, function (el, index) {
    const categoryTitle = el.urlkey.toLowerCase();
    const activeLocale = self.props.activeLocale;
    let title = null;
    if (queryParam !== undefined) {
      title = queryParam.toLowerCase();
    }

    if(categoryTitle === title && el.language === activeLocale){
      matched = true;
      self.setState({
        activeCategoryName: categoryTitle,
        activeCategory: el,
        notFound: false,
        isLoading: false,
        isEmpty: false
      });
    } else if(index === count && !matched){
      self.setState({
        isEmpty: true,
        isLoading: false
      });
    }
  });
}
}

Related Query

More Query from same tag