-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix amount prop update #382
Conversation
fczuardi
commented
May 31, 2018
- closes Amount selector, value should change if the props value is update after mount #381
@@ -57,6 +57,10 @@ class AmountSelectors extends React.Component { | |||
this.onChange(Math.min(value, this.props.max), this.updateDisplayValue); | |||
}; | |||
|
|||
componentWillReceiveProps(nextProps) { | |||
this.onChange(nextProps.value, this.updateDisplayValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this cause an infinite loop if props.onChange
updates props.value
?
Also, componentWillReceiveProps
will be deprecated in React 17. Let's avoid using it for new code:
https://reactjs.org/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes
https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding the possible loop, a listener for a value change that also immediately sets the value feels wrong, but anyways, the existing component(webapp) dont trigger an onChange, so I guess it is ok if we dont trigger one as well, I will just update state without calling the change handlers.
175558f
to
db16d39
Compare
affects: @crave/farmblocks-amount-selectors
affects: @crave/farmblocks-amount-selectors
… mount affects: @crave/farmblocks-amount-selectors
affects: @crave/farmblocks-amount-selectors
db16d39
to
29be50c
Compare