Created
September 23, 2018 17:13
-
-
Save whisher/d70f38cb7cb326de3ec06f8d64de6747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App extends Component { | |
_isMounted = false; | |
constructor(props) { | |
... | |
} | |
... | |
componentDidMount() { | |
this._isMounted = true; | |
const { searchTerm } = this.state; | |
this.setState({ searchKey: searchTerm }); | |
this.fetchSearchTopStories(searchTerm); | |
} | |
componentWillUnmount() { | |
this._isMounted = false; | |
} | |
... } | |
fetchSearchTopStories(searchTerm, page = 0) { | |
axios(`${PATH_BASE}${PATH_SEARCH}?${PARAM_SEARCH}${searchTerm}&${PARAM_PAGE}${pa\ | |
ge}&${PARAM_HPP}${DEFAULT_HPP}`) | |
.then(result => this._isMounted && this.setSearchTopStories(result.data)) | |
.catch(error => this._isMounted && this.setState({ error })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment