Avatar component
- React course
- Beginner
- Lesson 14/84
- 5 min
Write the avatar component and show a name and role.
Avatar component
In the previous lesson you wrote the Avatar skeleton. Now you'll improve it to show the name and role together. The avatar sits at the centre of the card.
The avatar is a small block at the top of the profile card: a name, a role and optionally an image. We skip the image and use only text in this project.
In later lessons we'll place this Avatar inside ProfileCard.
Avatar styling
Giving the avatar className="avatar" lets us style it with CSS. We don't write styles in this project but add className to keep the skeleton ready.
The two <p> tags inside the component show the name and role on separate lines. We'll replace this simple structure with a list in later lessons.
Now let's write the code and export the Avatar.
Practice Complete the Avatar
Complete the skeleton. Write a component called Avatar that returns <div className="avatar"> with <p>Ayşe</p> and <p>Geliştirici</p> inside. Don't forget to export.
Starter code
// Write the Avatar component hereSample solution
function Avatar() {
return <div className="avatar"><p>Ayşe</p><p>Geliştirici</p></div>;
}
export default Avatar;Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the Avatar show?
- Only a date
- Name and role Correct answer
- Only a button
- Only an image
Explanation: The Avatar shows name and role.
2 Avatar skeleton
The avatar sits inside a ____.
The avatar sits inside a div.
Explanation: The avatar sits inside a div.
3 Match the Avatar pieces
| Term | Meaning |
|---|---|
div |
Wrapper |
className |
Class |
p |
Line |
export |
Export |