Skip to content

Instantly share code, notes, and snippets.

@ericdfields
Last active September 28, 2016 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdfields/21076c1e54afff80e2916ad000cec9f5 to your computer and use it in GitHub Desktop.
Save ericdfields/21076c1e54afff80e2916ad000cec9f5 to your computer and use it in GitHub Desktop.
Replace nested react component using higher order component
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} />
}
}
class OriginalComponent extends Component {
defaultProps = {
documentTitle: (doc) => `Document #{doc.id}`
}
render = () => {
<div>
{ documents.map( doc => <DocumentThumbnail title={ this.props.documentTitle(doc) } /> ) }
</div>
}
}
@ericdfields
Copy link
Author

Thanks for the help, Dan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment