Wednesday, July 3, 2024
HomeLanguagesReactHow to Add Star Rating in Next.js ?

How to Add Star Rating in Next.js ?

In this article, we are going to learn how we can add Star Rating in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. 

Approach: To add our ratings we are going to use the react-stars package. The react-stars package helps us to integrate different types of ratings. So first, we will install the react-stars package and then we will add star ratings on our homepage.

Create NextJS Application: You can create a new NextJs project using the below command:

npx create-next-app gfg

 

Install the required package: Now we will install the react-stars package using the below command:

npm i react-stars

Project Structure: It will look like this.

Adding the Star Ratings: After installing the package we can easily add ratings in our app. For this example, we are going to add star ratings to our homepage.

index.js




import React from 'react';
import ReactStars from 'react-stars'
  
export default function SkeletonLoading(){
  return (
    <div>
      <h2>NextJs Star Ratings - neveropen</h2>
      <ReactStars
        count={5}
        size={24}
        color2={'#ffd700'} />
    </div>
  )
}


Explanation: In the above example first, we are importing our ReactStars component from the installed package. After that, we are using the component and setting the count, size, and color. Then we are displaying the Star Ratings.

Steps to run the application: Run the below command in the terminal to run the app.

npm run dev

Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments