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

Fix: respect defaultValue in Select and MultiSelect #522

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add useUpdateEffect hook
  • Loading branch information
ariser committed Jan 17, 2025
commit 21ba8b29b966092e53a485dd359f0395e77e7162
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -29,5 +29,8 @@ module.exports = {
singleReturnOnly: false,
},
],
"react-hooks/exhaustive-deps": ["warn", {
"additionalHooks": "(useUpdateEffect)"
}]
},
};
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./useUpdateEffect";
15 changes: 15 additions & 0 deletions src/hooks/useUpdateEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect, useRef } from "react";

export const useUpdateEffect: typeof useEffect = (effect, deps) => {
Copy link
Collaborator Author

@ariser ariser Jan 17, 2025

Choose a reason for hiding this comment

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

@vineethasok there are no custom hooks in click-ui as of now, so this is a vital point.
I find both custom hooks, and useUpdateEffect in particular, to be quite useful in certain cases. WDYT? Are you ok with adding a new module with hooks?

I can find other ways to deal with the bug, but in my mind running this effect on updates only is exactly the way to fix it.

const isFirstMount = useRef(true);

useEffect(() => {
if (isFirstMount) {
isFirstMount.current = false;
return;
}

return effect();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
};