Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created January 8, 2018 22:36
Show Gist options
  • Select an option

  • Save crobinson42/6b55f952550c0ef570d627cf1251ee56 to your computer and use it in GitHub Desktop.

Select an option

Save crobinson42/6b55f952550c0ef570d627cf1251ee56 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { connect } from 'react-redux'
class UserContainer extends Component {
componentDidMount() {
if (!this.props.user)
this.props.getUser()
}
render () {
if (!this.props.user)
return <div>Loading...</div>
return this.props.children
}
}
export default connect(
state => ({
user: state.user,
}),
{
getUser(),
}
)(UserContainer)
import React from 'react'
import UserContainer from 'containers/user/UserContainer.jsx'
const UserPage = () => (
<UserContainer>
This will only show if the user is loaded...
</UserContainer>
)
export default UserPage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment