-
Notifications
You must be signed in to change notification settings - Fork 419
Expand file tree
/
Copy pathCartLink.js
More file actions
executable file
·48 lines (43 loc) · 1.3 KB
/
CartLink.js
File metadata and controls
executable file
·48 lines (43 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { useState, useEffect } from 'react'
import { ContextProviderComponent, SiteContext } from '../context/mainContext'
import { FaShoppingCart, FaCircle } from 'react-icons/fa';
import Link from "next/link"
import { colors } from '../theme'
const { primary } = colors
function CartLink(props) {
const [renderClientSideComponent, setRenderClientSideComponent] = useState(false)
useEffect(() => {
setRenderClientSideComponent(true)
}, [])
let { context: { numberOfItemsInCart = 0 }} = props
return (
(<div>
<div className="fixed
sm:top-53 right-24 desktop:right-flexiblemargin
top-40 z-10">
<div className="flex flex-1 justify-end pr-4 relative">
<Link href="/cart" aria-label="Cart">
<FaShoppingCart />
</Link>
{
renderClientSideComponent && numberOfItemsInCart > Number(0) && (
<FaCircle color={primary} size={12} suppressHydrationWarning />
)
}
</div>
</div>
</div>)
);
}
function CartLinkWithContext(props) {
return (
<ContextProviderComponent>
<SiteContext.Consumer>
{
context => <CartLink {...props} context={context} />
}
</SiteContext.Consumer>
</ContextProviderComponent>
)
}
export default CartLinkWithContext