Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix: refresh cache memory leak example (#784)
Browse files Browse the repository at this point in the history
* docs(RefreshCache): fix guide memory leak

* fix(RefreshCache): fix memory leak
  • Loading branch information
samouss authored Jan 2, 2018
1 parent 349bf21 commit cf228ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docgen/src/guide/Refreshing_cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class App extends Component {
}

componentDidMount() {
setInterval(() => this.setState({ refresh: true }), 5000);
this.interval = setInterval(() => this.setState({ refresh: true }), 5000);
}

componentWillUnmount() {
clearInterval(this.interval);
}

onSearchStateChange = () => {
Expand Down
6 changes: 5 additions & 1 deletion stories/RefreshCache.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class App extends Component {
}

componentDidMount() {
setInterval(
this.interval = setInterval(
() =>
this.setState(prevState => ({
refresh: prevState.count === 5,
Expand All @@ -147,6 +147,10 @@ class App extends Component {
);
}

componentWillUnmount() {
clearInterval(this.interval);
}

render() {
return (
<InstantSearch
Expand Down

0 comments on commit cf228ac

Please sign in to comment.