ReactJS Evergreen Avatar Component
React Evergreen is a popular front-end library with a set of React components for building beautiful products as this library is flexible, sensible defaults, and User friendly. Avatar components are used to represent users only. We can use the following approach in ReactJS to use the Evergreen Avatar Component.
- className: It is used to pass the class name for this component.
- src: It is used to pass the address of the image for an image element or avatar.
- size: It is used to indicate the size of the avatar.
- name: It is used to denote the name used for the initials and title attribute.
- hashValue: It is used to denote the value used for the hash function.
- color: It is used to denote the color used for the avatar.
- getInitials: It is a function that is used to get the initials based on the name.
- forceShowInitials: It is used to force show the initials when this is set to true.
- sizeLimitOneCharacter: It is used to use a single initial for the avatar when the size is smaller than this number.
- shape: It is used to denote the shape of the avatar component. It can be round or square.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install evergreen-ui
Project Structure: It will look like the following.
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
Step to Run Application: Run the application using the following command from the root directory of the project:
Output: Now open your browser and go to http://localhost:3000/, you will see the following output: