Monte9 / react-native-ratings

Tap and Swipe Ratings component for React Native.
https://expo.io/@monte9/react-native-ratings
MIT License
903 stars 196 forks source link

Reset rating after every use #77

Open minimalistech opened 5 years ago

minimalistech commented 5 years ago

Hi, I am showing images and using AirbnbRating to let users rate the images. I am not finding an easy way to set the rating to the default values after the user rates the first image. I wan to clear the yellow stars and show them all grey.

appielife commented 4 years ago

You can assign the prop 'default value' to a state For example defaultRating={this.state.rating} Now reset your state to 0 or whatever initial value you want

chai86 commented 4 years ago

@appielife How can i use this on custom type? https://github.com/Monte9/react-native-ratings/issues/89

mitchh commented 4 years ago

I believe that this fail comes down to these lines of code; the component internally sets itself to n stars but the value of props.defaultRating, when trying to "reset" it, is the same as before, so nothing updates. I hacked around it by temporarily setting defaultRating to something else, and then back, but it's not a very satisfactory solution. I'd offer up a PR (and maybe still will), but I'm not sure about the motivation for getDerivedStateFromProps and fear that I would break some clever animation thing if I did it more conventionally (going fully controlled or fully uncontrolled by props). The advice here may be relevant.

Jamal-ReachFirst commented 1 year ago

You can assign the prop 'default value' to a state For example defaultRating={this.state.rating} Now reset your state to 0 or whatever initial value you want

not working