File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -11,20 +11,29 @@ export function AddToCart() {
1111 const router = useRouter ( ) ;
1212 const { color, size } = useProductDetailPageContext ( ) ;
1313 const [ isLoading , setIsLoading ] = useState ( false ) ;
14+ const [ clickCount , setClickCount ] = useState ( 0 ) ;
1415
1516 useEffect ( ( ) => {
1617 track ( 'add_to_cart:viewed' ) ;
1718 } , [ ] ) ;
1819
1920 return (
20- < AddToCartButton
21- isLoading = { isLoading }
22- onClick = { async ( ) => {
23- setIsLoading ( true ) ;
24- track ( 'add_to_cart:clicked' ) ;
25- await addToCart ( { id : 'shirt' , color, size, quantity : 1 } ) ;
26- router . push ( '/cart' ) ;
27- } }
28- />
21+ < div className = "space-y-2" >
22+ < AddToCartButton
23+ isLoading = { isLoading }
24+ onClick = { async ( ) => {
25+ setIsLoading ( true ) ;
26+ setClickCount ( prev => prev + 1 ) ;
27+ track ( 'add_to_cart:clicked' ) ;
28+ await addToCart ( { id : 'shirt' , color, size, quantity : 1 } ) ;
29+ router . push ( '/cart' ) ;
30+ } }
31+ />
32+ { clickCount > 0 && (
33+ < div className = "text-sm text-gray-600 text-center" >
34+ Button clicked { clickCount } times
35+ </ div >
36+ ) }
37+ </ div >
2938 ) ;
3039}
You can’t perform that action at this time.
0 commit comments