ninjasort / react-star-rating

[Looking for Maintainers (email me)]: A simple star rating component built with React.
MIT License
173 stars 55 forks source link

Component needs defaultValue #10

Closed TimDaub closed 8 years ago

TimDaub commented 9 years ago

Imagine using this component in combination with flux stores.

There can be an initial value a user has previously set in another session that is now submitted to the component via the rating prop. Unfortunately though, when setting the rating prop initially without clicking on it (and triggering handleClick). this.state.ratingCache is not set. This has the effect that when the user hovers over a initially set rating component, it basically resets it to no rating at all.

So, there should be either a method/flag or what ever that makes sure that the initial value is set in the cache.

ninjasort commented 9 years ago

I agree. When I first created this, I wasn't so clear on the necessity to create stateless components. There are some flaws in the architecture that I'll be working to fix. Feel free to submit a PR if you have any new ideas. Thanks for the suggestion.

ghan commented 9 years ago

I ran into this issue too. It looks like the component has no componentWillReceiveProps() defined... I was able to fix my issue by adding

componentWillReceiveProps(nextProps) { this.setState({ disabled: nextProps.disabled, editing: nextProps.editing }); }