-
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: InformationPanelの内部ロジックをリファクタリングする #5289
base: master
Are you sure you want to change the base?
Conversation
7692615
to
19857fc
Compare
commit: |
19857fc
to
e1a7585
Compare
title, | ||
titleTag, | ||
type = 'info', | ||
togglable = false, |
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.
比較にしか利用されていないため、初期値代入をする必要がありませんでした
const handleClickTrigger = useCallback(() => { | ||
if (onClickTrigger) { | ||
onClickTrigger(active) | ||
} else { | ||
setActive(!active) | ||
} | ||
}, [active, onClickTrigger]) |
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.
TogglableButton内に移動しています
const styles = useMemo(() => { | ||
const withActive = informationPanel({ | ||
type, | ||
active: true, | ||
bold, | ||
}) | ||
const withInactive = informationPanel({ | ||
type, | ||
active: false, | ||
bold, | ||
}) | ||
|
||
const wrapperProps = { className } | ||
|
||
return { | ||
active: { | ||
wrapper: withActive.wrapper(wrapperProps), | ||
header: withActive.header(), | ||
heading: withActive.heading(), | ||
togglableButton: withActive.togglableButton(), | ||
content: withActive.content(), | ||
}, | ||
inactive: { | ||
wrapper: withInactive.wrapper(wrapperProps), | ||
header: withInactive.header(), | ||
heading: withInactive.heading(), | ||
togglableButton: withInactive.togglableButton(), | ||
content: withInactive.content(), | ||
}, | ||
} | ||
}, [bold, type, className]) |
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.
再生成する必要がないよう、active, inactiveのパターン両方を事前に生成しています
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.
またコンポーネントを分割する関係上、関数を渡すよりstringを渡すほうがmemo化が適切に動作する可能性が高いためこのようなロジックにしています
<MemoizedHeading tag={titleTag} id={titleId} className={currentStyles.heading} type={type}> | ||
{title} | ||
</MemoizedHeading> |
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.
Headingは再生成が必要になるパターンが少ないことが予想されるため、丸ごとmemo化しています
suffix={active ? <FaCaretUpIcon /> : <FaCaretDownIcon />} | ||
size="s" | ||
onClick={handleClickTrigger} | ||
aria-expanded={active} |
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.
もともとはtogglableのようなロジックでundefinedが設定される可能性がありましたが、このボタンが表示されている場合、togglableがfalsyになる場合はありえないため、調整しています
@Qs-F レビューできる自信なく…レビュワー差し替えました🙇 |
関連URL
概要
変更内容
確認方法