Last active
October 11, 2016 12:59
-
-
Save joevo2/abd53a618481d2450c04101d95290c10 to your computer and use it in GitHub Desktop.
This is just about scope :)
This file contains 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
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