Last active
October 3, 2018 21:16
-
-
Save slightlytyler/e8c076865ad1a4bc4f89a69bb96b2dfe to your computer and use it in GitHub Desktop.
Branch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @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