Skip to content

Instantly share code, notes, and snippets.

@cellog
Created January 14, 2017 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellog/4c40d117344067e6c2976e1c398d34cf to your computer and use it in GitHub Desktop.
Save cellog/4c40d117344067e6c2976e1c398d34cf to your computer and use it in GitHub Desktop.
a simple conditional rendering higher order component
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