-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
const id = getFieldId(props, {}, sequentialId); | ||
|
||
const hasErrorInRemainingLanguages = | ||
props.hasError || | ||
getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage); | ||
|
||
if (hasErrorInRemainingLanguages) { | ||
const shouldLanguagesExpand = |
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.
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( |
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.
uses our toggleState hook instead
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.
Cool how we do not change the specs at all BTW.
static defaultProps = { | ||
horizontalConstraint: 'scale', | ||
}; | ||
const [areCurrenciesExpanded, toggleCurrencies] = useToggleState( |
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.
Super nice naming.
})} | ||
</Spacings.Stack> | ||
</Constraints.Horizontal> | ||
LocalizedMoneyInput.parseMoneyValues = (moneyValues = [], locale) => |
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.
Ah. Was looking for where this went.
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 |
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.
we are here because one of these is true, so if we haven't already expanded currencies, we should expand
Summary
Refactors the
LocalizedMoneyInput
component to use hooks.