Skip to content

Instantly share code, notes, and snippets.

@davibe
Last active November 23, 2016 21:52
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 davibe/fff8b5b9b6691f63aea78f4f11c8ef64 to your computer and use it in GitHub Desktop.
Save davibe/fff8b5b9b6691f63aea78f4f11c8ef64 to your computer and use it in GitHub Desktop.
//works
const decorate = (Component, body={}) => {
class Wrapper extends React.Component {
constructor() { return super() }
render() { return <Component {...this.props} /> }
static getInitialProps = body.getInitialProps
}
for (const key in body) {
Wrapper.prototype[key] = body[key]
}
return Wrapper
}
// does not
const decorate = (Component, body={}) => {
class Wrapper extends React.Component {
constructor() { return super() }
render() { return <Component {...this.props} /> }
static getInitialProps = body.getInitialProps
}
Wrapper.prototype = body
return Wrapper
}
i get
TypeError: Cannot call a class as a function
at exports.default (/Users/dade/work/grocerest/grocerest-webapp/node_modules/babel-runtime/helpers/classCallCheck.js:7:11)
at Wrapper (/Users/dade/work/grocerest/grocerest-webapp/.next/dist/pages/index.js:109:36)
at /Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:305:16
at measureLifeCyclePerf (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:74:12)
at ReactCompositeComponentMixin._constructComponentWithoutOwner (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:304:14)
at ReactCompositeComponentMixin._constructComponent (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:279:21)
at ReactCompositeComponentMixin.mountComponent (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:187:21)
at Object.ReactReconciler.mountComponent (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactReconciler.js:47:35)
at ReactCompositeComponentMixin.performInitialMount (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:370:34)
at ReactCompositeComponentMixin.mountComponent (/Users/dade/work/grocerest/grocerest-webapp/node_modules/react/lib/ReactCompositeComponent.js:257:21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment