Skip to content

Instantly share code, notes, and snippets.

@thekevinscott
Last active August 8, 2016 13:00
Show Gist options
  • Save thekevinscott/795f169a7de50c7a5151cb847113d2d2 to your computer and use it in GitHub Desktop.
Save thekevinscott/795f169a7de50c7a5151cb847113d2d2 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { connect } from 'react-redux';
function getWrappedComponent(
component,
[
mapStateToProps,
mapDispatchToProps,
mergeProps,
options,
],
) {
return connect(
mapStateToProps,
mapDispatchToProps,
mergeProps,
{
...options,
withRef: true,
},
)(component);
}
const patchedConnect = (...args) => component => {
const WrappedComponent = getWrappedComponent(component, args);
class WrapperComponent extends Component {
render() {
return (
<WrappedComponent
{...this.props}
ref={c => { console.log(c); }}
/>
);
}
}
return WrapperComponent;
};
export default patchedConnect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment