Created
August 29, 2018 03:27
-
-
Save Shuumatsu/184b27aaaddf609c0cbca73d3a6a1f6a to your computer and use it in GitHub Desktop.
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
import { curry } from 'ramda' | |
import React from 'react' | |
import { withStateHandlers } from 'recompose' | |
import styled, { css } from 'styled-components' | |
const initialState = { retryCount: 1 } | |
const stateHandlers = { | |
reload: ({ retryCount }) => _ => ({ retryCount: retryCount + 1 }) | |
} | |
const hideComponent = Cmp => styled(Cmp)` | |
${css` | |
${props => (props.hide ? 'transition: opacity 0.75s; opacity: 0;' : 'opacity: 1;')}; | |
`}; | |
` | |
export default curry((errorCondition, RawCmp, RawError) => { | |
const Error = hideComponent(RawError) | |
const Cmp = hideComponent(RawCmp) | |
return withStateHandlers(initialState, stateHandlers)(({ retryCount, reload, ...rest }) => ( | |
<> | |
<Error hide={!errorCondition(rest)} key={-retryCount} action={reload} /> | |
<Cmp hide={errorCondition(rest)} key={retryCount} /> | |
</> | |
)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment