Skip to content

Commit 75f4dc0

Browse files
fix: address CodeRabbit review - throttle scroll, use Lucide icon, add hover effect
Signed-off-by: Vaishnavi Thakur <vaaishnavi4713@gmail.com>
1 parent d10f283 commit 75f4dc0

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

apps/web-dashboard/src/components/Layout/BackToTop.jsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { useState, useEffect } from 'react';
2+
import { ArrowUp } from 'lucide-react';
23

34
function BackToTop() {
45
const [isVisible, setIsVisible] = useState(false);
6+
const [isHovered, setIsHovered] = useState(false);
57

68
useEffect(() => {
9+
let ticking = false;
10+
711
const handleScroll = () => {
8-
if (window.scrollY > 300) {
9-
setIsVisible(true);
10-
} else {
11-
setIsVisible(false);
12+
if (!ticking) {
13+
window.requestAnimationFrame(() => {
14+
setIsVisible(window.scrollY > 300);
15+
ticking = false;
16+
});
17+
ticking = true;
1218
}
1319
};
1420

1521
window.addEventListener('scroll', handleScroll);
22+
handleScroll();
1623

1724
return () => {
1825
window.removeEventListener('scroll', handleScroll);
@@ -35,6 +42,8 @@ function BackToTop() {
3542
onClick={handleClick}
3643
title="Back to Top"
3744
aria-label="Back to Top"
45+
onMouseEnter={() => setIsHovered(true)}
46+
onMouseLeave={() => setIsHovered(false)}
3847
style={{
3948
position: 'fixed',
4049
bottom: '2rem',
@@ -46,15 +55,16 @@ function BackToTop() {
4655
borderRadius: '50%',
4756
width: '45px',
4857
height: '45px',
49-
fontSize: '1.2rem',
5058
cursor: 'pointer',
5159
boxShadow: '0 0 15px rgba(0, 245, 212, 0.4)',
5260
display: 'flex',
5361
alignItems: 'center',
5462
justifyContent: 'center',
63+
transform: isHovered ? 'scale(1.1)' : 'scale(1)',
64+
transition: 'transform 0.2s ease',
5565
}}
5666
>
57-
67+
<ArrowUp size={20} strokeWidth={2.5} />
5868
</button>
5969
);
6070
}

0 commit comments

Comments
 (0)