Last active
December 10, 2018 15:02
-
-
Save stephencweiss/844be18f4da56f985f534298d5e1fc45 to your computer and use it in GitHub Desktop.
Binding methods in React supplies the appropriate context so that a function can be passed around.
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
class App extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
} | |
this.searchDB = this.searchDB.bind(this); | |
this.handleClick = this.handleClick.bind(this); // This was the missing critical line | |
} | |
handleClick (type, param) { | |
if (type === "Search") { | |
this.searchDB(param); | |
} | |
else console.log('No type managed --> ', type); | |
} | |
searchDB (query) { | |
console.log(`The search query is --> `, query); | |
} | |
render () { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment