Skip to content

Commit a612cbd

Browse files
authored
Merge pull request #95 from zenml-io/fixup-wrap-use-callback
fix: wrap function with useCallback
2 parents 9c6d7a2 + bad93d1 commit a612cbd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.changeset/tame-pumas-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zenml-io/react-component-library": patch
3+
---
4+
5+
fix: wrap function with useCallback

src/components/Sidebar/SidebarContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, {
33
PropsWithChildren,
44
SetStateAction,
55
createContext,
6+
useCallback,
67
useContext,
78
useState
89
} from "react";
@@ -33,7 +34,7 @@ export function SidebarProvider({
3334
* then the sidebar gets automatically closed, instead of waiting for the user
3435
* to hover away from it before closing.
3536
*/
36-
function setIsOpen(newValue: Setter<boolean>): void {
37+
const setIsOpen = useCallback((newValue: Setter<boolean>): void => {
3738
_setIsOpen((currIsOpen) => {
3839
const value: boolean = getValueFromSetter(newValue, currIsOpen);
3940

@@ -44,7 +45,7 @@ export function SidebarProvider({
4445

4546
return value;
4647
});
47-
}
48+
}, []);
4849

4950
return (
5051
<SidebarContext.Provider value={{ isOpen, setIsOpen, isClosing }}>

0 commit comments

Comments
 (0)