-
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: FormDialogの内部処理を整理する #5321
base: master
Are you sure you want to change the base?
Conversation
b4642a8
to
67f0735
Compare
commit: |
67f0735
to
4364bcd
Compare
7ae0086
to
d77fb16
Compare
@@ -24,7 +24,7 @@ export const FormDialog: 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.
actionDisabledは最終的にButtonのdisabledとして設定されるだけであり、falseを指定する意味が薄かったため、初期化しないように修正しました
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分処理が無駄になっている
というデメリットのほうが大きそうだったので調整しています
const calcedResponseStatus = useMemo(() => { | ||
if (!responseMessage) { | ||
return { | ||
isProcessing: false, | ||
visibleMessage: false, | ||
} | ||
} | ||
|
||
if (responseMessage.status === 'processing') { | ||
return { | ||
isProcessing: true, | ||
visibleMessage: false, | ||
} | ||
} | ||
|
||
return { | ||
isProcessing: false, | ||
visibleMessage: true, | ||
// HINT: statusがprocessingではない === success or errorであることが確定する | ||
// success or error の場合、text属性も必ず存在する | ||
status: responseMessage.status as 'success' | 'error', | ||
message: (responseMessage as { text: string }).text, | ||
} | ||
}, [responseMessage]) |
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化するようにしました。
他コンポーネントでも同様の変換処理が有るため、別PRでカスタムhookを作成する予定です
関連URL
概要
変更内容
確認方法