11/* eslint-disable import/no-unresolved */
22
33import { createRoot } from 'react-dom/client' ;
4- import React , { useRef , useEffect } from 'react' ;
4+ import React , { useRef , useEffect , useState } from 'react' ;
55
66import type { HovercardsProps } from '../dist/index.react.d' ;
77import { useHovercards , Hovercards } from '../dist/index.react' ;
@@ -20,37 +20,55 @@ function App() {
2020 // eslint-disable-next-line no-console
2121 const { attach } = useHovercards ( { onFetchProfileSuccess : ( hash ) => console . log ( hash ) } ) ;
2222 const containerRef = useRef ( null ) ;
23+ const attacherRef = useRef ( null ) ;
24+ const [ hashes , setHashes ] = useState ( [
25+ '33252cd1f33526af53580fcb1736172f06e6716f32afdd1be19ec3096d15dea5' ,
26+ 'c3bb8d897bb538896708195dd9eb162f585654611c50a3a1c9a16a7b64f33270' ,
27+ '20e74a1399c883caeeba81b57007bcaa058940dcdffca01babfddbaefa5c3c4a' ,
28+ ] ) ;
2329
2430 useEffect ( ( ) => {
2531 if ( containerRef . current ) {
2632 attach ( containerRef . current ) ;
2733 }
2834 } , [ attach ] ) ;
2935
36+ function recycle ( ) {
37+ const newHashes = [ ...hashes ] ;
38+
39+ for ( let i = newHashes . length - 1 ; i > 0 ; i -- ) {
40+ const j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
41+ [ newHashes [ i ] , newHashes [ j ] ] = [ newHashes [ j ] , newHashes [ i ] ] ;
42+ }
43+
44+ setHashes ( newHashes ) ;
45+
46+ if ( attacherRef . current ) {
47+ attach ( attacherRef . current ) ;
48+ }
49+ }
50+
3051 return (
3152 < div style = { { display : 'flex' , flexDirection : 'column' , alignItems : 'center' , gap : '5rem' } } >
3253 < div >
3354 < div ref = { containerRef } style = { { display : 'flex' , flexDirection : 'column' , gap : '5rem' } } >
34- < img
35- src = "https://www.gravatar.com/avatar/33252cd1f33526af53580fcb1736172f06e6716f32afdd1be19ec3096d15dea5?s=60& d = retro & r = g "
36- width = "60"
37- height = "60"
38- alt = "Gravatar"
39- />
40- < img
41- src = "https://www.gravatar.com/avatar/c3bb8d897bb538896708195dd9eb162f585654611c50a3a1c9a16a7b64f33270"
42- width = "60"
43- height = "60"
44- alt = "Gravatar"
45- />
55+ { hashes . map ( ( hash ) => (
56+ < img
57+ key = { hash }
58+ src = { `https://gravatar.com/avatar/${ hash } ?s=128&d=retro&r=g` }
59+ width = "60"
60+ height = "60"
61+ alt = "Gravatar"
62+ />
63+ ) ) }
4664 </ div >
4765 </ div >
4866 < Hovercards
4967 style = { { display : 'flex' , flexDirection : 'column' , alignItems : 'center' , gap : '5rem' } }
5068 { ...props }
5169 >
5270 < img
53- src = "https://www. gravatar.com/avatar/20e74a1399c883caeeba81b57007bcaa058940dcdffca01babfddbaefa5c3c4a?s=60& d = retro & r = g "
71+ src = "https://gravatar.com/avatar/20e74a1399c883caeeba81b57007bcaa058940dcdffca01babfddbaefa5c3c4a?s=60& d = retro & r = g "
5472 width = "60"
5573 height = "60"
5674 alt = "Gravatar"
@@ -62,6 +80,12 @@ function App() {
6280 @WellyTest
6381 </ div >
6482 </ Hovercards >
83+
84+ < div className = "gravatar-hovercard-attacher" >
85+ < button type = "button" onClick = { recycle } >
86+ Recycle
87+ </ button >
88+ </ div >
6589 </ div >
6690 ) ;
6791}
0 commit comments