Ravenous part 4 - features to add to Ravenous

Hi everyone,

I try to do the list of features to add at the end of ravenous part 4.

One of them is saying “Clicking on a different sorting option automatically requeries the Yelp API, rather than having to manually click “Let’s Go” again” .

So i put searchYelp() to access the Yelp API in my handleSortByChange method like this :

handleSortByChange(sortByOptionValue) {
        this.setState({
            sortBy: sortByOptionValue
        });
        this.props.searchYelp(this.state.term, this.state.location, this.state.sortBy);
    }

Is it the good way to resolve this ?

Because when i test and click on a sorting option, my businesses change on the page but not like it should be…ex: Highest Rated will not be in the good order with all the 20 businesses (only a few of them will work…this a very weird).

2 Likes

handleSortByChange(sortByOptionValue) {
this.setState({
sortBy: sortByOptionValue
}, () => {
this.props.searchYelp(this.state.term, this.state.location, this.state.sortBy);
});

}
4 Likes

Thank you, I was so stuck on this step!

I had to lookup the (setState documentation to understand that what you did is add the optional callback function.

But without your answer, I wouldn’t even know to look for it.