11import { useEffect , useState } from 'react' ;
22
33export default function ScrollToTop ( ) {
4- const [ visible , setVisible ] = useState ( false ) ;
4+ const [ visible , setVisible ] = useState ( false ) ;
55
6- useEffect ( ( ) => {
7- const onScroll = ( ) => setVisible ( window . scrollY > 300 ) ;
8- window . addEventListener ( 'scroll' , onScroll , { passive : true } ) ;
9- onScroll ( ) ;
10- return ( ) => window . removeEventListener ( 'scroll' , onScroll ) ;
11- } , [ ] ) ;
6+ useEffect ( ( ) => {
7+ const onScroll = ( ) => setVisible ( window . scrollY > 300 ) ;
8+ window . addEventListener ( 'scroll' , onScroll , { passive : true } ) ;
9+ onScroll ( ) ;
10+ return ( ) => window . removeEventListener ( 'scroll' , onScroll ) ;
11+ } , [ ] ) ;
1212
13- if ( ! visible ) return null ;
13+ if ( ! visible ) return null ;
1414
15- return (
16- < button
17- aria-label = "Scroll to top"
18- onClick = { ( ) => window . scrollTo ( { top : 0 , behavior : 'smooth' } ) }
19- style = { { zIndex : 9999 } }
20- className = "
15+ return (
16+ < button
17+ aria-label = "Scroll to top"
18+ onClick = { ( ) => window . scrollTo ( { top : 0 , behavior : 'smooth' } ) }
19+ style = { { zIndex : 9999 } }
20+ className = "
2121 fixed right-5 bottom-6
2222 w-15 h-15 rounded-lg border-none
2323 bg-emerald-300 text-black shadow-lg
@@ -26,17 +26,17 @@ export default function ScrollToTop() {
2626 transition-transform duration-200 ease-in-out
2727 focus:outline-none focus:ring-2 focus:ring-white/20 focus:ring-offset-2
2828 "
29- >
30- < svg
31- xmlns = "http://www.w3.org/2000/svg"
32- stroke = "currentColor"
33- width = "35"
34- height = "35"
35- fill = "currentColor"
36- viewBox = "0 0 640 640"
37- >
38- < path d = "M342.6 81.4C330.1 68.9 309.8 68.9 297.3 81.4L137.3 241.4C124.8 253.9 124.8 274.2 137.3 286.7C149.8 299.2 170.1 299.2 182.6 286.7L288 181.3L288 552C288 569.7 302.3 584 320 584C337.7 584 352 569.7 352 552L352 181.3L457.4 286.7C469.9 299.2 490.2 299.2 502.7 286.7C515.2 274.2 515.2 253.9 502.7 241.4L342.7 81.4z" />
39- </ svg >
40- </ button >
41- ) ;
42- }
29+ >
30+ < svg
31+ xmlns = "http://www.w3.org/2000/svg"
32+ stroke = "currentColor"
33+ width = "35"
34+ height = "35"
35+ fill = "currentColor"
36+ viewBox = "0 0 640 640"
37+ >
38+ < path d = "M342.6 81.4C330.1 68.9 309.8 68.9 297.3 81.4L137.3 241.4C124.8 253.9 124.8 274.2 137.3 286.7C149.8 299.2 170.1 299.2 182.6 286.7L288 181.3L288 552C288 569.7 302.3 584 320 584C337.7 584 352 569.7 352 552L352 181.3L457.4 286.7C469.9 299.2 490.2 299.2 502.7 286.7C515.2 274.2 515.2 253.9 502.7 241.4L342.7 81.4z" />
39+ </ svg >
40+ </ button >
41+ ) ;
42+ }
0 commit comments