From 1b962fe89bb8e2699d3f64ab4f5d0b3117e89c23 Mon Sep 17 00:00:00 2001 From: Pierre Berard Date: Tue, 4 Dec 2018 19:34:17 +0100 Subject: [PATCH] Fixes componentDidUpdate when count is updated --- src/react-stars.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/react-stars.js b/src/react-stars.js index ae36507..0ee7783 100644 --- a/src/react-stars.js +++ b/src/react-stars.js @@ -70,7 +70,7 @@ class ReactStars extends Component { componentWillReceiveProps(props) { this.setState({ - stars: this.getStars(props.value), + stars: this.getStars(props.value, props.count), value: props.value, halfStar: { at: Math.floor(props.value), @@ -102,12 +102,14 @@ class ReactStars extends Component { return stars } - getStars(activeCount) { + getStars(activeCount, count) { + count = count || this.state.config.count + if (typeof activeCount === 'undefined') { activeCount = this.getRate() } let stars = [] - for (let i = 0; i < this.state.config.count; i++) { + for (let i = 0; i < count; i++) { stars.push({ active: i <= activeCount - 1 })