Skip to content

Commit 8cea8ac

Browse files
committed
fix: wrap function with useCallback
we use it inside a useEffect dependency array, and now that it's no longer coming from `useState`, it gets reset everytime & the logic breaks. the wrapping in useCallback fixes this.
1 parent 9c6d7a2 commit 8cea8ac

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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)