3
2

More than 1 year has passed since last update.

Reactで星評価機能を実装する

Last updated at Posted at 2023-01-21

react-awesome-stars-ratingというライブラリを使用して、
下記のような星評価機能を実装しました。
https://github.com/fedoryakubovich/react-awesome-stars-rating

8b6e208377656b92b5b0dfbbfc642489.gif

使い方

npmにreact-awesome-stars-ratingをインストールする。

npm install react-awesome-stars-rating

ReactStarsRatingコンポーネントをimportして使用する。

Star.jsx
import { useState } from "react";
import ReactStarsRating from 'react-awesome-stars-rating';

export const Star = () => {
  const onChange = (value) => {
    setValue(value)
  };

  const [value, setValue] = useState(3);

  return (
    <>
      <ReactStarsRating onChange={onChange} value={value} />
    </>
  )
}

星の色や数も変更することができます。
設定値についてはドキュメントに記載されています。
https://github.com/fedoryakubovich/react-awesome-stars-rating#documentation

57d1125b4b7f554c204daea04444cb7b.gif

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2