Created
February 22, 2017 00:53
-
-
Save distributedlife/99f27950a7b9d205a9819a12033898c3 to your computer and use it in GitHub Desktop.
React component that only provides lifecycle events
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'; | |
import { browserHistory } from 'react-router'; | |
import makeLifecyleComponent from './lifecycle-only'; | |
const redirectToRoot = (props) => { | |
if (!props.isLoggedIn) { | |
browserHistory.push('/'); | |
} | |
}; | |
export const RedirectToLoginWhereNoToken = connect((state) => ({ | |
isLoggedIn: !!state.auth.token, | |
}))(makeLifecyleComponent('RedirectToLoginWhereNoToken', { componentDidMount: redirectToRoot })); |
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'; | |
export default (name, lifecycleEvents) => React.createClass({ | |
displayName: name, | |
render() { | |
return null; | |
}, | |
componentDidMount() { | |
return lifecycleEvents.componentDidMount(this.props); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment