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

chore: Dialog周辺コンポーネントのロジックを整理する #5318

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

AtsushiM
Copy link
Member

関連URL

概要

変更内容

確認方法

@yagimushi yagimushi force-pushed the chore-refactoring-DialogWrapper branch 2 times, most recently from 26197a7 to a650f37 Compare January 22, 2025 06:46
Copy link

pkg-pr-new bot commented Jan 22, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5318

commit: 2e54a1d

@yagimushi yagimushi force-pushed the chore-refactoring-DialogWrapper branch from a650f37 to 2e54a1d Compare January 22, 2025 06:50
onPressEscape = () => {
/* noop */
},
onPressEscape,
Copy link
Member Author

Choose a reason for hiding this comment

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

onPressEscapeが存在しない場合、そもそも実行する必要すらない箇所だったので、初期化を削除しました

@@ -81,44 +71,39 @@ export const DialogContentInner: FC<DialogContentInnerProps & ElementProps> = ({
className,
...rest
}) => {
const { layoutStyleProps, innerStyle, backgroundStyle } = useMemo(() => {
const { layoutStyle, innerStyle, backgroundStyle } = useMemo(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

style属性とclass属性を同時にmemo化するメリットがない箇所だったので分割しました

}
onPressEscape()
}, [isOpen, onPressEscape]),
useMemo(() => (onPressEscape && isOpen ? onPressEscape : undefined), [isOpen, onPressEscape]),
Copy link
Member Author

Choose a reason for hiding this comment

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

なるべくキャッシュが有効になるよう、onPressEscapeが存在し、かつ実行するひつようがあるときだけ参照渡しするようにしました

@@ -25,8 +25,9 @@ const dialogHeader = tv({
],
})

export const DialogHeader: React.FC<Props> = ({ title, subtitle, titleTag, titleId }) => {
const style = dialogHeader()
export const DialogHeader = React.memo<Props>(({ title, subtitle, titleTag, titleId }) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

DialogのHeaderはほぼ再レンダリングが不要な場合が多いと予想されるため、丸ごとmemo化しました

Comment on lines +21 to +22
const onClickTrigger = useCallback(() => setActive(true), [])
const onClickClose = useCallback(() => setActive(false), [])
Copy link
Member Author

Choose a reason for hiding this comment

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

再生成が完全に不要な箇所だったため、memo化しています

useEffect(() => {
if (!handleKeyPress) {
Copy link
Member Author

@AtsushiM AtsushiM Jan 22, 2025

Choose a reason for hiding this comment

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

実行する必要が一切ない場合でもevent listnerが実行されるパターンが存在したため、早期終了を追加しました

@AtsushiM AtsushiM marked this pull request as ready for review January 22, 2025 22:50
@AtsushiM AtsushiM requested a review from a team as a code owner January 22, 2025 22:50
@AtsushiM AtsushiM requested review from misako0927 and s-sasaki-0529 and removed request for a team January 22, 2025 22:50
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.

1 participant