-
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: ActionDialogの内部処理を整理する #5324
base: master
Are you sure you want to change the base?
Conversation
84983bc
to
703c0e3
Compare
commit: |
@@ -24,7 +24,7 @@ export const ActionDialog: React.FC<Props & ElementProps> = ({ | |||
onClickClose, | |||
onPressEscape = onClickClose, | |||
responseMessage, | |||
actionDisabled = false, | |||
actionDisabled, |
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.
最終的にButtonのdisabledに設定されるだけだったため、初期化の意味が薄く、削除しました
if (!props.isOpen) { | ||
return | ||
if (props.isOpen) { | ||
onClickClose() |
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していますが
- 直後の処理の判定を逆転させているだけであり、理解が一手遅れる
- !とreturn分の処理が余計にかかる
というデメリットのほうが大きそうだったため調整しています
onClickAction(onClickClose) | ||
}, [onClickAction, onClickClose]) | ||
const isRequestProcessing = responseMessage && responseMessage.status === 'processing' | ||
const calcedResponseStatus = useMemo(() => { |
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.
responseMessageの判定が煩雑になっていたため、扱いやすい形に変換、memo化しています。
この処理は他のコンポーネントでもよくあるもののため、カスタムhookを別PRで作成予定です
const onClickOpen = useMemo( | ||
() => (onClickTrigger ? () => onClickTrigger(open) : open), | ||
[onClickTrigger, open], | ||
) |
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.
useCallbackではなくuseMemoにしています。
こうすることでどの場合でもonClickOpen実行時に行っているif判定を事前に行えます
関連URL
概要
変更内容
確認方法