Skip to content

Instantly share code, notes, and snippets.

@ankitghike
Created October 4, 2018 08:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ankitghike/28eb43bf36b41e7671f06d0fbde54b00 to your computer and use it in GitHub Desktop.
Save ankitghike/28eb43bf36b41e7671f06d0fbde54b00 to your computer and use it in GitHub Desktop.
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