Skip to content
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

Merged
merged 4 commits into from
Jun 15, 2018
Merged

Fix amount prop update #382

merged 4 commits into from
Jun 15, 2018

Conversation

fczuardi
Copy link
Contributor

@@ -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);
Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@fczuardi fczuardi Jun 12, 2018

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.

@fczuardi fczuardi force-pushed the fix-amount-prop-update branch from 175558f to db16d39 Compare June 12, 2018 18:51
fczuardi and others added 4 commits June 15, 2018 13:16
… mount

affects: @crave/farmblocks-amount-selectors
affects: @crave/farmblocks-amount-selectors
@alcferreira alcferreira force-pushed the fix-amount-prop-update branch from db16d39 to 29be50c Compare June 15, 2018 16:22
@vNakamura vNakamura merged commit 1953a3f into master Jun 15, 2018
@vNakamura vNakamura deleted the fix-amount-prop-update branch June 15, 2018 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amount selector, value should change if the props value is update after mount
3 participants