Skip to content

Update Rating.js#39

Open
ashikshafi08 wants to merge 1 commit intodennisivy:masterfrom
ashikshafi08:patch-1
Open

Update Rating.js#39
ashikshafi08 wants to merge 1 commit intodennisivy:masterfrom
ashikshafi08:patch-1

Conversation

@ashikshafi08
Copy link
Copy Markdown

@ashikshafi08 ashikshafi08 commented Mar 30, 2023

Much more dynamic solution for generating the stars.

import React from "react";

export default function Rating({ value, text, color }) {
  const stars = [];
  for (let i = 0; i < 5; i++) {
    if (value >= i + 1) {
      stars.push(<i key={i} style={{ color }} className="fas fa-star"></i>);
    } else if (value >= i + 0.5) {
      stars.push(
        <i
          key={i}
          style={{ color }}
          className="fas fa-star-half-alt"
        ></i>
      );
    } else {
      stars.push(<i key={i} style={{ color }} className="far fa-star"></i>);
    }
  }

  return (
    <div className="rating">
      {stars}
      <span style={{ paddingLeft: "10px" }}>{text && text}</span>
    </div>
  );
}

Much more dynamic solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant