GriddleGriddle / Griddle

Simple Grid Component written in React
http://griddlegriddle.github.io/Griddle/
MIT License
2.5k stars 378 forks source link

componentWillReceiveProps uses empty filter when using an external filter #818

Closed Gration1 closed 3 years ago

Gration1 commented 6 years ago

Griddle version

0.8.2

The following code is called when setting the filter, so when useExternal is set it just executes the externalSetFilter callback function. This works as expected.

/* if we have a filter display the max page and results accordingly */
setFilter: function setFilter(filter) {
    var updatedResults = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];

    if (this.props.useExternal) {
        this.props.externalSetFilter(filter);
        return;
    }

...

However when my callback function updates the results, causing the Griddle component to re-render, it uses this check and calls the above function again with this.state.filter which is empty.

componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
    // Check if results props changed
    if (nextProps.results !== this.props.results) {
        this.setFilter(this.state.filter, nextProps.results);
    }
whiteb38 commented 6 years ago

Also facing this issue. Workaround:

if (this.props.useExternal && this.props.externalSetFilter) {
    this.props.externalSetFilter(filter);
    return;
}