Created
January 14, 2017 07:58
-
-
Save cellog/4c40d117344067e6c2976e1c398d34cf to your computer and use it in GitHub Desktop.
a simple conditional rendering higher order component
This file contains 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 React from 'react' | |
import { connect } from 'react-redux' | |
export default isActive => ({ component, ...props }) => { | |
const Component = component | |
const NullComponent = ({ '@@__isActive': active, ...props }) => ( | |
active ? <Component {...props} /> : null | |
) | |
const R = connect((state, props) => { | |
return { | |
...props, | |
'@@__isActive': __loaded && isActive(state, props), | |
} | |
})(NullComponent) | |
return <R {...props} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment