1- import React from 'react' ;
2- import { useEffect , useState } from 'react' ;
1+ import React from 'react'
2+ import { useEffect , useState } from 'react'
33import { ArrowUpIcon } from '@heroicons/react/outline'
44
55function BackToTopButton ( ) {
6- const [ backToTopButton , setBackToTopButton ] = useState ( false ) ;
6+ const [ backToTopButton , setBackToTopButton ] = useState ( false )
77
8- useEffect ( ( ) => {
9- window . addEventListener ( " scroll" , ( ) => {
10- if ( window . scrollY > 100 ) {
11- setBackToTopButton ( true )
12- } else {
13- setBackToTopButton ( false )
14- }
15- } )
16- } , [ ] )
8+ useEffect ( ( ) => {
9+ window . addEventListener ( ' scroll' , ( ) => {
10+ if ( window . scrollY > 100 ) {
11+ setBackToTopButton ( true )
12+ } else {
13+ setBackToTopButton ( false )
14+ }
15+ } )
16+ } , [ ] )
1717
18- const scrollUp = ( ) => {
19- window . scrollTo ( {
20- top : 0 ,
21- behavior : " smooth"
22- } )
23- }
18+ const scrollUp = ( ) => {
19+ window . scrollTo ( {
20+ top : 0 ,
21+ behavior : ' smooth' ,
22+ } )
23+ }
2424
25- return (
26- < div >
27- { backToTopButton && (
28-
29- < button onClick = { scrollUp } className = "fixed bottom-12 right-12 w-12 h-12 text-5xl text-white bg-sky-500 rounded-full flex items-center justify-center hover:shadow-xl hover:ring-2 hover:ring-rose-500 hover:ring-offset-2 focus:ring-2 focus:ring-rose-500 focus:ring-offset-2 dark:bg-gray-700" > < ArrowUpIcon className = "h-8 w-8" /> </ button >
30-
31-
32- ) }
33-
34-
35- </ div >
36- )
25+ return (
26+ < div >
27+ { backToTopButton && (
28+ < button
29+ onClick = { scrollUp }
30+ className = "fixed bottom-12 right-12 flex h-12 w-12 items-center justify-center rounded-full bg-sky-500 text-5xl text-white hover:shadow-xl hover:ring-2 hover:ring-rose-500 hover:ring-offset-2 focus:ring-2 focus:ring-rose-500 focus:ring-offset-2 dark:bg-gray-700"
31+ >
32+ { ' ' }
33+ < ArrowUpIcon className = "h-8 w-8" /> { ' ' }
34+ </ button >
35+ ) }
36+ </ div >
37+ )
3738}
3839
39- export default BackToTopButton ;
40+ export default BackToTopButton
0 commit comments