import React from 'react'; import FriendIndexItem from './friend_index_item'; class FriendIndex extends React.Component { constructor() { super(); this.state = { friends: null }; } componentDidMount() { this.props .requestUserFriends(this.props.userId) .then(res => this.setState({ friends: Object.values(res.users) })); } componentDidUpdate(prevProps) { if (prevProps.match.params.userUrl !== this.props.match.params.userUrl) { this.props .requestUserFriends(this.props.userId) .then(res => this.setState({ friends: Object.values(res.users) })); } } render() { if (this.state.friends === null) return null; const friends = this.state.friends.map(friend => { return ; }); return (
Friends ยท

{friends.length}

{friends}
); } } export default FriendIndex;