Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to clear rating #31

Closed
sspenst opened this issue Oct 25, 2022 · 2 comments
Closed

No way to clear rating #31

sspenst opened this issue Oct 25, 2022 · 2 comments

Comments

@sspenst
Copy link

sspenst commented Oct 25, 2022

How can I clear the rating back to the initial empty state? Previously I could use ratingValue to clear when clicking the current rating:

  const handleRating = (value: number) => {
    if (value === rating) {
      setRating(0);
    } else {
      setRating(value);
    }
  };

But with the removal of ratingValue in v4.1.0 I'm no longer sure how to do this.

Please let me know if there is another way to clear the rating on the latest version!

@awran5
Copy link
Owner

awran5 commented Oct 28, 2022

Hi @sspenst Sorry for the late response.

Please first update to v5.1.5

And follow this example:

function MyComponent() {
  const [rating, setRating] = useState(0)

  const handleRating = (rate: number) => {
    setRating(rate)
  }

  const handleReset = () => {
    // Set the initial value
    setRating(0)
  }

  return (
    <div className='App'>
      {/* set initial value */}
      <Rating onClick={handleRating} initialValue={rating} />

      <button onClick={handleReset}>reset</button>
    </div>
  )
}

@sspenst
Copy link
Author

sspenst commented Oct 29, 2022

Thanks @awran5 ! I've added a reset button and it seems to work fine

@sspenst sspenst closed this as completed Oct 29, 2022
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

No branches or pull requests

2 participants