-
Notifications
You must be signed in to change notification settings - Fork 89
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
Common select fixes #1449
Common select fixes #1449
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1449 +/- ##
=======================================
Coverage 94.48% 94.49%
=======================================
Files 210 210
Lines 3971 3975 +4
Branches 1628 1629 +1
=======================================
+ Hits 3752 3756 +4
Misses 219 219 ☔ View full report in Codecov by Sentry. |
🙏 |
@@ -69,9 +69,16 @@ const useSelect = ({ | |||
simpleValue, | |||
compareValues, | |||
}) => { | |||
const [state, originalDispatch] = useReducer(reducer, { optionsTransformer, propsOptions }, init); | |||
const [propsOptions, setPropsCache] = useState(initialOptions); | |||
const [state, originalDispatch] = useReducer(reducer, { optionsTransformer, propsOptions: initialOptions }, init); | |||
const dispatch = (action) => originalDispatch({ ...action, optionsTransformer }); |
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.
We can pass the compareValues
here so no need to pass it to all following dispatches
if (!isEqual(state.options, propsOptions)) { | ||
if (state.isInitialLoaded) { |
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.
These two if
s can be merged
const dispatch = (action) => originalDispatch({ ...action, optionsTransformer }); | ||
|
||
useEffect(() => { | ||
if (!isEqual(initialOptions, propsOptions)) { |
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.
Can it lead to performance issues? 🤔
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.
For massive arrays of options it could, but as it stands infinite render loops are way worse.
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.
yeah, they are 😄
30d1a88
to
23a38f5
Compare
🎉 This PR is included in version 3.22.4 🎉 The release is available on |
Fixes #1448
Description
compareValues
included in select promises payload