Skip to content

Instantly share code, notes, and snippets.

@e-schultz
Created August 20, 2019 15:48
Show Gist options
  • Select an option

  • Save e-schultz/c5dbd7d5bed711e2783b93be5195c6a8 to your computer and use it in GitHub Desktop.

Select an option

Save e-schultz/c5dbd7d5bed711e2783b93be5195c6a8 to your computer and use it in GitHub Desktop.
react hooks - lifecycle
export default SearchComponent extends Component {
constructor(props) {
super(props);
this.state = {
results: []
}
}
componentDidMount() {
this.query(this.props.id)
}
componentDidUpdate(prevProps) {
if(this.prevProps.id !== this.props.id) {
this.query(this.props.id);
}
}
query(id) {
this.setState({isLoading: true})
fetch(`/some/url/${id}`)
.then(r=>r.json())
.then(r=>this.setState({
results: results
});
)
}
}
@priccis

priccis commented Aug 29, 2019

Copy link
Copy Markdown

In line 22, results: r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment