MyCrypto/common/components/hocs/Conditional.tsx
HenryNguyen5 da93fb1684 Prettier Reformat (#619)
* Add repo wide prettier command to prepush

* Make config file explict, remove formatAll to prepush
2017-12-18 17:29:26 -06:00

26 lines
662 B
TypeScript

import React, { Component } from 'react';
interface RequiredProps {
condition: boolean;
conditionalProps: {
[key: string]: any;
};
}
/**
* Optional
*/
export const withConditional = <WrappedComponentProps extends {}>(
PassedComponent: React.ComponentType<WrappedComponentProps>
) =>
class extends Component<WrappedComponentProps & RequiredProps, {}> {
public render() {
const { condition, conditionalProps, ...passedProps } = this.props as any;
return condition ? (
<PassedComponent {...{ ...passedProps, ...(conditionalProps as object) }} />
) : (
<PassedComponent {...passedProps} />
);
}
};