Last active
September 28, 2016 21:36
-
-
Save ericdfields/21076c1e54afff80e2916ad000cec9f5 to your computer and use it in GitHub Desktop.
Replace nested react component using higher order component
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
export class FaxDocumentViewerApp extends Component { | |
defaultProps = { | |
documentTitle: (doc) => `${doc.fax_type} — ${moment(doc.created_at).format('MMM D YYYY [@] h:mm a')}` | |
} | |
render = () => { | |
<OriginalComponent {...this.props} /> | |
} | |
} | |
export class HubDocumentViewerApp extends Component { | |
defaultProps = { | |
documentTitle: (doc) => moment(doc.created_at).format('MMM D YYYY [@] h:mm a') | |
} | |
render = () => { | |
<OriginalComponent {...this.props} /> | |
} | |
} |
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 OriginalComponent extends Component { | |
defaultProps = { | |
documentTitle: (doc) => `Document #{doc.id}` | |
} | |
render = () => { | |
<div> | |
{ documents.map( doc => <DocumentThumbnail title={ this.props.documentTitle(doc) } /> ) } | |
</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the help, Dan!