Skip to content

Commit ce96c87

Browse files
committed
chore: add useIsClient hook
1 parent 08c9fee commit ce96c87

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/components/EnergyConsumptionChart.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react"
2+
import { useEffect, useState } from "react"
23
import {
34
BarElement,
45
CategoryScale,
@@ -38,6 +39,16 @@ const EnergyConsumptionChart = () => {
3839
const { locale } = useRouter()
3940
const isRtl = isLangRightToLeft(locale as Lang)
4041

42+
const useIsClient = () => {
43+
const [isClient, setClient] = useState(false)
44+
45+
useEffect(() => {
46+
setClient(true)
47+
}, [])
48+
49+
return isClient
50+
}
51+
4152
// chart rawData, according to different breakpoints
4253
const rawData = useBreakpointValue({
4354
base: [
@@ -240,7 +251,9 @@ const EnergyConsumptionChart = () => {
240251
mb={{ base: 4, md: 0 }}
241252
>
242253
{/* TODO: isRtl ? data?.reverse() : data */}
243-
<Bar options={chartOptions} data={chartData} updateMode="none" />
254+
{useIsClient() && (
255+
<Bar options={chartOptions} data={chartData} updateMode="none" />
256+
)}
244257
</Box>
245258
</Center>
246259

0 commit comments

Comments
 (0)