Skip to content

Commit

Permalink
Fix deferred load setState warning
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Oct 19, 2017
1 parent 5f1e8ed commit 227e35b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,27 @@ storiesOf('Griddle main', module)
})
.add('with local, delayed data', () => {
class DeferredGriddle extends React.Component<GriddleProps<FakeData>, { data?: FakeData[] }> {
private timeout;

constructor(props) {
super(props);
this.state = {};
}

componentDidMount() {
this.resetData();
}

componentWillUnmount() {
this.timeout && clearTimeout(this.timeout);
}

resetData = () => {
this.setState({ data: null });

setTimeout(() => {
this.timeout && clearTimeout(this.timeout);

this.timeout = setTimeout(() => {
this.setState({ data: this.props.data });
}, 2000);
}
Expand Down

0 comments on commit 227e35b

Please sign in to comment.