-
Notifications
You must be signed in to change notification settings - Fork 141
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
chore: DatePickerの内部処理を整理する #5329
base: master
Are you sure you want to change the base?
Conversation
c38d089
to
35a48fe
Compare
35a48fe
to
8d05c8b
Compare
commit: |
// has no space on bottom side | ||
inputRect.bottom + contentHeihgt > innerHeight && | ||
// top side space bigger than bottom side | ||
inputRect.top > innerHeight - inputRect.bottom |
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.
元々は変数化されていたのでifの実行前に余計な計算がされる可能性がありました。
if条件内に移動することで必要最小限の実行になるように修正しています
const style = useMemo(() => portal(), []) | ||
|
||
const styleAttr = useMemo( | ||
() => ({ | ||
top: `${position.top}px`, | ||
left: `${position.left}px`, | ||
}), | ||
[position.left, position.top], | ||
) |
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.
不必要にtailwindの実行がされる可能性があったため、memoを分割しています
if (!containerRef.current) { | ||
return | ||
if (containerRef.current) { | ||
setPosition(getPortalPosition(inputRect, containerRef.current.offsetHeight)) |
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.
直後の処理の条件の逆の早期returnになっていたため、整理しています
const firstCalendarButton = calendarButtons[0] | ||
const lastCalendarButton = calendarButtons[calendarButtons.length - 1] |
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.
直後のifで早期returnされる場合、利用されない変数だったため、位置を移動しています
|
||
const switchCalendarVisibility = useCallback((isVisible: boolean) => { |
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.
明確にtrue, falseを渡す箇所が多く、依存関係の処理などがわかりにくくなっていたため、open, closeを明確に行う別関数を用意しました
関連URL
概要
変更内容
確認方法