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

refactor(localized-money-input): use hooks #974

Merged
merged 4 commits into from
Jul 30, 2019
Merged

Conversation

montezume
Copy link
Contributor

Summary

Refactors the LocalizedMoneyInput component to use hooks.

const id = getFieldId(props, {}, sequentialId);

const hasErrorInRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage);

if (hasErrorInRemainingLanguages) {
const shouldLanguagesExpand =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was unnecessary. we are already inside of an if for hasErrorInRemainingLanguages, so there's no point of this


const [areLanguagesExpanded, setAreLanguagesExpanded] = React.useState(
const [areLanguagesExpanded, toggleLanguages] = useToggleState(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

uses our toggleState hook instead

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

Cool how we do not change the specs at all BTW.

static defaultProps = {
horizontalConstraint: 'scale',
};
const [areCurrenciesExpanded, toggleCurrencies] = useToggleState(
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nice naming.

})}
</Spacings.Stack>
</Constraints.Horizontal>
LocalizedMoneyInput.parseMoneyValues = (moneyValues = [], locale) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. Was looking for where this went.

@montezume
Copy link
Contributor Author

ah VRTs showed a problem with warning state

);
if (hasErrorInRemainingCurrencies || hasWarningInRemainingCurrencies) {
// this update within render replaces the old `getDerivedStateFromProps` functionality
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are here because one of these is true, so if we haven't already expanded currencies, we should expand

@montezume montezume merged commit e89bb66 into master Jul 30, 2019
@montezume montezume deleted the ml-localized-money-hook branch July 30, 2019 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants