Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class UserPage extends Component {
  2. componentWillMount() {
  3. this.props.dispatch(fetchUser(this.props.user.id));
  4. }
  5.  
  6. render() {
  7. <UserProfile name={this.props.user.name} />
  8. }
  9. }
  10.  
  11. const mapStateToProps = (state, ownProps) => {
  12. return {
  13. user: _.find(state.users, (user) => user.id == ownProps.params.userId)),
  14. };
  15. };
  16.  
  17. const mapDispatchToProps = (dispatch) => {
  18. return {
  19. dispatch
  20. };
  21. };
  22.  
  23. export default connect(mapStateToProps, mapDispatchToProps)(UserPage);
  24.  
  25. class UserPage extends Component {
  26. componentWillMount() {
  27. this.props.dispatch(fetchUser(this.props.user.id));
  28. }
  29.  
  30. renderUser() {
  31. if (this.props.user) {
  32. return (
  33. <UserProfile name={this.props.user.name} />
  34. )
  35. }
  36. }
  37.  
  38. render() {
  39. return (
  40. <div>{this.renderUser()}</div>
  41. )
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement