Skip to content

Commit 6d410f1

Browse files
committed
Typescript
1 parent 37d562f commit 6d410f1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/components/Footer/Hamburger.component.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,39 @@ const Hamburger = () => {
2323
const [isExpanded, setisExpanded] = useState(false);
2424
const [hidden, setHidden] = useState('invisible');
2525
const [isAnimating, setIsAnimating] = useState(false);
26-
const animationTimeoutRef = useRef<NodeJS.Timeout | null>(null);
26+
const animationTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
27+
null,
28+
);
2729

2830
useEffect(() => {
2931
if (isExpanded) {
3032
setHidden('');
3133
setIsAnimating(true);
32-
34+
3335
// Clear any existing timeout
3436
if (animationTimeoutRef.current) {
3537
clearTimeout(animationTimeoutRef.current);
3638
}
37-
39+
3840
// Set a timeout for the animation duration
3941
animationTimeoutRef.current = setTimeout(() => {
4042
setIsAnimating(false);
4143
}, 1000); // Match this with the animation duration
4244
} else {
4345
setIsAnimating(true);
44-
46+
4547
// Clear any existing timeout
4648
if (animationTimeoutRef.current) {
4749
clearTimeout(animationTimeoutRef.current);
4850
}
49-
51+
5052
// Set a timeout for the animation duration and hiding
5153
animationTimeoutRef.current = setTimeout(() => {
5254
setHidden('invisible');
5355
setIsAnimating(false);
5456
}, 1000); // Match this with the animation duration
5557
}
56-
58+
5759
// Cleanup function to clear timeout when component unmounts
5860
return () => {
5961
if (animationTimeoutRef.current) {
@@ -67,7 +69,7 @@ const Hamburger = () => {
6769
if (isAnimating) {
6870
return;
6971
}
70-
72+
7173
/**
7274
* Anti-pattern: setisExpanded(!isExpanded)
7375
* Even if your state updates are batched and multiple updates to the enabled/disabled state are made together
@@ -136,7 +138,10 @@ const Hamburger = () => {
136138
}}
137139
onKeyDown={(event) => {
138140
// 'Enter' key or 'Space' key
139-
if ((event.key === 'Enter' || event.key === ' ') && !isAnimating) {
141+
if (
142+
(event.key === 'Enter' || event.key === ' ') &&
143+
!isAnimating
144+
) {
140145
setisExpanded((prevExpanded) => !prevExpanded);
141146
}
142147
}}

0 commit comments

Comments
 (0)