Skip to content

Instantly share code, notes, and snippets.

@erikras
Last active April 27, 2016 10:22
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 erikras/60504cbdcdf5ab29235371d990f43244 to your computer and use it in GitHub Desktop.
Save erikras/60504cbdcdf5ab29235371d990f43244 to your computer and use it in GitHub Desktop.
The HOC Drill Pattern [BEFORE]
import React, { Component } from 'react'
import MyWrappedComponent from './MyWrappedComponent'
export default class MyContainer extends Component {
constructor() {
// bind handlers
this.handleLoad = this.handleLoad.bind(this)
this.handleSave = this.handleSave.bind(this)
this.handleClear = this.handleClear.bind(this)
}
handleLoad() {
// somehow call load() on MyWrappedComponent
}
handleSave() {
// somehow call save() on MyWrappedComponent
}
handleClear() {
// somehow call clear() on MyWrappedComponent
}
render() {
return (
<div>
<button onClick={this.handleLoad}>Load</button>
<button onClick={this.handleSave}>Save</button>
<button onClick={this.handleClear}>Clear</button>
<MyWrappedComponent/>
</div>
)
}
}
import React, { Component } from 'react'
import { hocLibrary } from 'some-hoc-library'
@hocLibrary({ config: 'parameters' })
export default class MyWrappedComponent extends Component {
load() {
// load something
}
save() {
// save something
}
clear() {
// clear something
}
render() {
return <div>Gorgeous UI</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment