Last active
June 29, 2016 03:15
-
-
Save robin-pham/0ff09f61623e2125b1eb8df16dcbd267 to your computer and use it in GitHub Desktop.
How do I reuse all these onClick functions? I don't want to copy and paste the same functions over and over.
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
import React, { Component } from 'react'; | |
import { getAsyncRandomReport } from 'thirdPartyLibrary'; | |
class UniqueComponentOne extends Component { | |
constructor(props){ | |
super(props); | |
this.onClickRefresh = this.onClickRefresh.bind(this); | |
this.onClickUpdate = this.onClickUpdate.bind(this); | |
} | |
report = getAsyncRandomReport(); | |
onClickRefresh(){ | |
/* lotsof reusable business logic that involves other values in the state | |
------ codecodecodecodecode -------------------------------------------- | |
*/ | |
this.report.refresh(); | |
} | |
onClickUpdate(){ | |
/* lotsof reusable business logic that involves other values in the state | |
------ codecodecodecodecode -------------------------------------------- | |
*/ | |
this.report.update(); | |
} | |
render() { | |
return ( | |
<Button onClick={this.onClickUpdate} /> | |
<Button onClick={this.onClickRefresh} /> | |
); | |
} | |
} |
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
import React, { Component } from 'react'; | |
import { getAsyncRandomReport } from 'thirdPartyLibrary'; | |
class UniqueComponentTwo extends Component { | |
constructor(props){ | |
super(props); | |
this.onClickRefresh = this.onClickRefresh.bind(this); | |
this.onClickDance = this.onClickDance.bind(this); | |
} | |
report = getAsyncRandomReport(); | |
onClickRefresh(){ | |
/* lotsof reusable business logic that involves other values in the state | |
------ codecodecodecodecode -------------------------------------------- | |
*/ | |
this.report.refresh(); | |
} | |
onClickDance(){ | |
/* lotsof reusable business logic that involves other values in the state | |
------ codecodecodecodecode -------------------------------------------- | |
*/ | |
this.report.dance(); | |
} | |
render() { | |
return ( | |
<Button onClick={this.onClickDance} /> | |
<Button onClick={this.onClickRefresh} /> | |
); | |
} | |
} |
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
import React, { Component } from 'react'; | |
import { getAsyncRandomReport } from 'thirdPartyLibrary'; | |
class UniqueComponentThree extends Component { | |
constructor(props){ | |
super(props); | |
this.onClickBurn = this.onClickBurn.bind(this); | |
this.onClickDance = this.onClickDance.bind(this); | |
} | |
report = getAsyncRandomReport(); | |
onClickBurn(){ | |
/* lotsof reusable business logic that involves other values in the state | |
------ codecodecodecodecode -------------------------------------------- | |
*/ | |
this.report.burn(); | |
} | |
onClickDance(){ | |
/* lotsof reusable business logic that involves other values in the state | |
------ codecodecodecodecode -------------------------------------------- | |
*/ | |
this.report.dance(); | |
} | |
render() { | |
return ( | |
<Button onClick={this.onClickBurn} /> | |
<Button onClick={this.onClickDance} /> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment