Skip to content

Instantly share code, notes, and snippets.

@joevo2
Last active October 11, 2016 12:59
Show Gist options
  • Save joevo2/abd53a618481d2450c04101d95290c10 to your computer and use it in GitHub Desktop.
Save joevo2/abd53a618481d2450c04101d95290c10 to your computer and use it in GitHub Desktop.
This is just about scope :)
setData = data => {
console.log('setData', data)
this.setState({ test: data })
}
getData = () => {
const setData = this.setData
Axios
.get('...')
.then(function(result) {
console.log('getData', result)
setData(result)
})
}
// OR SIMPLER
getData = () => {
Axios
.get('...')
.then( result => {
console.log('getData', result)
this.setData(result)
})
}
// OR BETTER
getData = () => {
Axios
.get('...')
.then( this.setData )
}
// Another method
getData = () => {
let _this = this
Axios
.get('...')
.then( result => {
this.setState({ test: result })
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment