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: SortDropdownの内部処理をリファクタリングする #5311

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

Conversation

AtsushiM
Copy link
Member

関連URL

概要

変更内容

確認方法

@yagimushi yagimushi force-pushed the chore-refactoring-SortDropdown branch from fd60537 to e610f52 Compare January 21, 2025 22:15
Copy link

pkg-pr-new bot commented Jan 21, 2025

Open in Stackblitz

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

commit: 2da43ca

@yagimushi yagimushi force-pushed the chore-refactoring-SortDropdown branch from e610f52 to 2da43ca Compare January 21, 2025 22:18
@@ -50,21 +54,23 @@ export const useSortDropdown = ({ sortFields, defaultOrder, onApply, decorators
const [innerSelectedField, setInnerSelectedField] = useState<string>()
const [innerCheckedOrder, setCheckedInnerOrder] = useState<Props['defaultOrder']>(defaultOrder)

useMemo(() => {
useEffect(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

useMemoのreturnを何も使っておらず、かつ内容の処理が完全に副作用しかないため、useEffectに置き換えました

Comment on lines +84 to +100
const newFields = innerFields.map((field) => {
if (field.label === newLabel) {
if (!field.selected) {
return {
...field,
selected: true,
}
}
} else if (field.selected) {
return {
...field,
selected: false,
}
}

return field
})
Copy link
Member Author

Choose a reason for hiding this comment

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

必ず配列内すべてのオブジェクトを置き換えていましたが、必要な場合のみ再生成するようにロジックを変更しています。

Comment on lines +113 to +115
const onChangeSortOrderRadio = useCallback<ChangeEventHandler<HTMLInputElement>>((e) => {
setCheckedInnerOrder(e.currentTarget.value as Props['defaultOrder'])
}, [])
Copy link
Member Author

Choose a reason for hiding this comment

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

setCheckedInnerOrder をそのまま渡すのではなく、実際に利用する形式に変更しました。
eventからvalue属性を参照することで依存関係がない状態にすることで再生成しないようにしています

@AtsushiM AtsushiM marked this pull request as ready for review January 21, 2025 22:23
@AtsushiM AtsushiM requested a review from a team as a code owner January 21, 2025 22:23
@AtsushiM AtsushiM requested review from moshisora and hiroki0525 and removed request for a team January 21, 2025 22:23
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