Created
March 28, 2016 21:59
-
-
Save st8998/3a0fd06428fd67d427c3 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
@connect( | |
(state, props) => ({ user: find(propEq('id', Number(props.params.id)), state.users) }), | |
{ requestUser } | |
) | |
export default class UserProfile extends Component { | |
static contextTypes = { | |
router: React.PropTypes.object | |
}; | |
componentWillMount() { | |
// come from another page to /profile/:id | |
if (!this.props.user) this.props.requestUser(this.props.params.id) | |
.catch(() => this.context.router.push('/notfound')) | |
} | |
componentWillUpdate(nextProps) { | |
// change id param of the route /profile/1 -> /profile/122 | |
if (!nextProps.user) | |
this.props.requestUser(nextProps.params.id) | |
.catch(() => this.context.router.push('/notfound')) | |
} | |
render() { | |
return <Profile user={this.props.user}></Profile> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment