scrimba
Build an Instagram clone in React
Profile Page Component
Implementing the Follow Count on a User's Profile
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Implementing the Follow Count on a User's Profile
AboutCommentsNotes
Implementing the Follow Count on a User's Profile
Expand for more info
src
components
profile
header.js
run
preview
console
import React, { useState, useEffect } from 'react';
import Skeleton from 'react-loading-skeleton';
import useUser from '../../hooks/use-user';

export default function Header({
photosCount,
followerCount,
setFollowerCount,
username,
profile: { docId: profileDocId, userId: profileUserId, fullName, following = [] }
}) {
const { user } = useUser();
const [isFollowingProfile, setIsFollowingProfile] = useState(false);
const activeBtnFollow = user.username && user.username !== username;

return (
<div className="grid grid-cols-3 gap-4 justify-between mx-auto max-w-screen-lg">
<div className="container flex justify-center">
<img
className="rounded-full h-40 w-40 flex"
alt={`${username} profile picture`}
src={`/images/avatars/${username}.jpg`}
/>
</div>
<div className="flex items-center justify-center flex-col col-span-2">
<div className="container flex items-center">
<p className="text-2xl mr-4">{username}</p>
{activeBtnFollow && (
<button
className="bg-blue-500 font-bold text-sm rounded text-white w-20 h-8"
type="button"
onClick={() => console.log('I am a button')}
>
{isFollowingProfile ? 'Unfollow' : 'Follow'}
</button>
)}
</div>
<div className="container flex mt-4">
{followerCount === undefined || following === undefined ? (
<Skeleton count={1} width={677} height={24} />
) : (
<>
<p className="mr-10">
<span className="font-bold">{photosCount}</span> photos
</p>
<p className="mr-10">
<span className="font-bold">{followerCount}</span> {' '}
{followerCount === 1 ? 'follower' : 'followers'}
</p>
<p className="mr-10">
<span className="font-bold">{following.length}</span> following
</p>
</>
)}
</div>
<div className="container mt-4">
<p className="font-medium">{!fullName ? <Skeleton count={1} height={24} /> : fullName}</p>
</div>
</div>
</div>
);
}
Console
/p/raphael
-9:08