Created
October 4, 2018 08:17
-
-
Save ankitghike/28eb43bf36b41e7671f06d0fbde54b00 to your computer and use it in GitHub Desktop.
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
class Container extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
componentDidMount() { | |
if(!this.props.friendsFetched) { | |
FriendsService.fetchFriends().then((data) => { | |
this.props.onFriendsFetch(data); | |
}); | |
} | |
} | |
render() { | |
const { friends } = this.props; | |
return ( | |
<View style={styles.flex}> | |
<FriendsHeader count={friends.length} text='My friends' /> | |
{friends.map((friend) => (<FriendRow {...friend} />)) } | |
</View> | |
); | |
} | |
} | |
const mapStateToProps = (state) => ({ | |
...state.friendsReducer | |
}); | |
const mapActionToProps = (dispatch) => ({ | |
onFriendsFetch: (data) => { | |
dispatch(FriendActions.onFriendsFetch(data)); | |
} | |
}); | |
export default connect(mapStateToProps, mapActionToProps)(Container); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment