What is happening with bind here? Ravenous Part 3 Task 9

On line 54, we have to use bind within onClick{} , for the referenced function (handleSortByChange).
However, for handleLocationChange and handleTermChange, the bind() is done in the contractor/ line 20.

Could anyone please explain what bind actually does in a little more detail?

I’m leaning along the lines of the fact that you can’t just have onClick={this.handleSortByChange}, as there would be no way to then add the parameter in. You can’t however, just have onClick={this.handleSortByChange(sortByOptionValue}, because then you’ll get a setState Loop, which is the error I get. I think an alternative around this would be to have another function which references the handleSortByChange right?

Many thanks


bump? anyone got any ideas haha

I’m not too sure if this will help, but I had the same question actually and looked up the difference between binding inline vs in the constructor and found these to be helpful:

1 Like

Thanks a lot will have a look at this!