-
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: SortDropdownの内部処理をリファクタリングする #5311
base: master
Are you sure you want to change the base?
Conversation
fd60537
to
e610f52
Compare
commit: |
e610f52
to
2da43ca
Compare
@@ -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(() => { |
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.
useMemoのreturnを何も使っておらず、かつ内容の処理が完全に副作用しかないため、useEffectに置き換えました
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 | ||
}) |
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 onChangeSortOrderRadio = useCallback<ChangeEventHandler<HTMLInputElement>>((e) => { | ||
setCheckedInnerOrder(e.currentTarget.value as Props['defaultOrder']) | ||
}, []) |
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.
setCheckedInnerOrder
をそのまま渡すのではなく、実際に利用する形式に変更しました。
eventからvalue属性を参照することで依存関係がない状態にすることで再生成しないようにしています
関連URL
概要
変更内容
確認方法