joyent-portal/ui/src/shared/redux-form-proxy.js

37 lines
615 B
JavaScript
Raw Normal View History

const React = require('react');
const transformPropsWith = require('transform-props-with');
const {
default: tx
} = transformPropsWith;
const Proxy = tx(props => {
const {
input,
meta,
...rest
} = props;
return {
...input,
...meta,
...rest
};
});
const isReduxForm = (props) =>
props.hasOwnProperty('input') || props.hasOwnProperty('meta');
module.exports = (Component) => {
const ProxiedComponent = Proxy(Component);
return (props) => {
return isReduxForm(props) ? (
<ProxiedComponent {...props} />
) : (
<Component {...props} />
);
};
};