-
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-text-input): use hooks #958
Conversation
|
||
static isEmpty = isEmpty; | ||
if (hasErrorInRemainingLanguages) { |
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 replaces the 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.
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.
Thanks for sharing
event.target.language = this.props.language; | ||
this.props.onChange(event); | ||
event.target.language = props.language; | ||
props.onChange(event); |
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.
Nit: could useCallback with lang and onChange as dep.
defaultExpansionState = true; | ||
} else if (props.defaultExpandLanguages) { | ||
defaultExpansionState = true; | ||
} |
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.
For me it would be easier to follow when inlining this at L129 and OR joining both prop values?
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.
Yeah it can be as simple as:
const defaultExpansionState = props.hideLanguageExpansionControls || props.defaultExpandLanguages;
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.
Nice to see how the component gets simpler!
|
||
static getId = getId; | ||
const toggleLanguages = React.useCallback(() => { |
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.
Hmm do we really need this callback? Can't we use the setter directly?
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.
I guess it's a micro optimization. If the expansion state doesn't change, then the function can remove memoized?
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.
I'm okay with removing it, just let me know 😄
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.
It’s not a big deal, I personally don’t see a need of wrapping a setter with another setter, as there is no extra logic involved.
|
||
static isEmpty = isEmpty; | ||
if (hasErrorInRemainingLanguages) { |
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.
Thanks for sharing
|
||
static omitEmptyTranslations = omitEmptyTranslations; | ||
if (shouldLanguagesExpand !== areLanguagesExpanded) { |
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.
Let's add the link to the docs here, otherwise it might be confusing to see updating the state on rendering.
eed923c
to
a357c60
Compare
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.
🧽
a357c60
to
074c531
Compare
event.target.language = props.language; | ||
onChange(event); | ||
}, | ||
[props.language, onChange] |
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 only need to destructure onChange
, for whatever reason. I suppose the lint plugin has some bugs.
Summary
Refactors the
LocalizedTextInput
container to use react hooks