diff --git a/lib/utils/plugins.js b/lib/utils/plugins.js index 0a405dc479f4..31d563db4dbc 100644 --- a/lib/utils/plugins.js +++ b/lib/utils/plugins.js @@ -370,9 +370,27 @@ export const middleware = store => next => action => { nextMiddleware(middlewares)(action); }; +// expose decorated component instance to the higher-order components +function exposeDecorated(Component) { + return class extends React.Component { + constructor(props, context) { + super(props, context); + this.onRef = this.onRef.bind(this); + } + onRef(decorated) { + if (this.props.onDecorated) { + this.props.onDecorated(decorated); + } + } + render() { + return React.createElement(Component, Object.assign({}, this.props, {ref: this.onRef})); + } + }; +} + function getDecorated(parent, name) { if (!decorated[name]) { - let class_ = parent; + let class_ = exposeDecorated(parent); modules.forEach(mod => { const method = 'decorate' + name;