react-native-ratings icon indicating copy to clipboard operation
react-native-ratings copied to clipboard

Reset rating after every use

Open minimalistech opened this issue 6 years ago • 4 comments
trafficstars

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.

minimalistech avatar Nov 14 '19 05:11 minimalistech

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

appielife avatar Jan 02 '20 13:01 appielife

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

chai86 avatar Mar 30 '20 21:03 chai86

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.

mitchh avatar Oct 31 '20 00:10 mitchh

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

Jamal-ReachFirst avatar Dec 20 '22 10:12 Jamal-ReachFirst