File tree Expand file tree Collapse file tree 2 files changed +15
-12
lines changed Expand file tree Collapse file tree 2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 1
1
import React from "react"
2
- import { useEffect , useState } from "react"
3
2
import {
4
3
BarElement ,
5
4
CategoryScale ,
@@ -25,6 +24,8 @@ import type { Lang } from "@/lib/types"
25
24
import { wrapLabel } from "@/lib/utils/charts"
26
25
import { isLangRightToLeft } from "@/lib/utils/translations"
27
26
27
+ import { useIsClient } from "@/hooks/useIsClient"
28
+
28
29
// ChartDataLabels required to display y-labels on top of bars
29
30
ChartJS . register (
30
31
CategoryScale ,
@@ -37,18 +38,9 @@ ChartJS.register(
37
38
const EnergyConsumptionChart = ( ) => {
38
39
const { t } = useTranslation ( "page-what-is-ethereum" )
39
40
const { locale } = useRouter ( )
41
+ const isClient = useIsClient ( )
40
42
const isRtl = isLangRightToLeft ( locale as Lang )
41
43
42
- const useIsClient = ( ) => {
43
- const [ isClient , setClient ] = useState ( false )
44
-
45
- useEffect ( ( ) => {
46
- setClient ( true )
47
- } , [ ] )
48
-
49
- return isClient
50
- }
51
-
52
44
// chart rawData, according to different breakpoints
53
45
const rawData = useBreakpointValue ( {
54
46
base : [
@@ -251,7 +243,7 @@ const EnergyConsumptionChart = () => {
251
243
mb = { { base : 4 , md : 0 } }
252
244
>
253
245
{ /* TODO: isRtl ? data?.reverse() : data */ }
254
- { useIsClient ( ) && (
246
+ { isClient && (
255
247
< Bar options = { chartOptions } data = { chartData } updateMode = "none" />
256
248
) }
257
249
</ Box >
Original file line number Diff line number Diff line change
1
+ import { useEffect , useState } from "react"
2
+
3
+ export const useIsClient = ( ) => {
4
+ const [ isClient , setClient ] = useState ( false )
5
+
6
+ useEffect ( ( ) => {
7
+ setClient ( true )
8
+ } , [ ] )
9
+
10
+ return isClient
11
+ }
You can’t perform that action at this time.
0 commit comments