Skip to content

Instantly share code, notes, and snippets.

@slightlytyler
Last active October 3, 2018 21:16
Show Gist options
  • Select an option

  • Save slightlytyler/e8c076865ad1a4bc4f89a69bb96b2dfe to your computer and use it in GitHub Desktop.

Select an option

Save slightlytyler/e8c076865ad1a4bc4f89a69bb96b2dfe to your computer and use it in GitHub Desktop.
Branch.js
// @flow
import type { Children } from 'react';
import Hidden from 'components/Hidden';
const renderNoop = () => null;
type Props = {
condition: any,
persistent?: boolean,
renderLeft: () => Children,
renderRight?: () => Children,
};
const defaultProps = {
persistent: false,
renderRight: renderNoop,
};
const Branch = (props: Props) => {
if (props.persistence) {
if (props.condition) {
return (
<>
{props.renderLeft()}
<Hidden>{props.renderRight()}</Hidden>
</>
);
}
return (
<>
<Hidden>{props.renderLeft()}</Hidden>
{props.renderRight()}
</>
);
}
return props.condition ? props.renderLeft() : props.renderRight()
};
Branch.defaultProps = defaultProps;
export default Branch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment