Skip to content

Commit 586a1c2

Browse files
[charts] Rename useIsClient (#16937)
1 parent 8a21f42 commit 586a1c2

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

packages/x-charts/src/ChartsText/ChartsText.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import { GetWordsByLinesParams, getWordsByLines } from '../internals/getWordsByLines';
5-
import { useIsClient } from '../hooks/useIsClient';
5+
import { useIsHydrated } from '../hooks/useIsHydrated';
66

77
export interface ChartsTextProps
88
extends Omit<
@@ -25,11 +25,11 @@ function ChartsText(props: ChartsTextProps) {
2525

2626
const { angle, textAnchor, dominantBaseline, ...style } = styleProps ?? {};
2727

28-
const isClient = useIsClient();
28+
const isHydrated = useIsHydrated();
2929

3030
const wordsByLines = React.useMemo(
31-
() => getWordsByLines({ style, needsComputation: isClient && text.includes('\n'), text }),
32-
[style, text, isClient],
31+
() => getWordsByLines({ style, needsComputation: isHydrated && text.includes('\n'), text }),
32+
[style, text, isHydrated],
3333
);
3434

3535
let startDy: number;

packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import composeClasses from '@mui/utils/composeClasses';
66
import { useThemeProps, useTheme, styled } from '@mui/material/styles';
77
import { useRtl } from '@mui/system/RtlProvider';
88
import { clampAngle } from '../internals/clampAngle';
9-
import { useIsClient } from '../hooks/useIsClient';
9+
import { useIsHydrated } from '../hooks/useIsHydrated';
1010
import { doesTextFitInRect, ellipsize } from '../internals/ellipsize';
1111
import { getStringSize } from '../internals/domUtils';
1212
import { useTicks, TickItemType } from '../hooks/useTicks';
@@ -238,7 +238,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
238238
const drawingArea = useDrawingArea();
239239
const { left, top, width, height } = drawingArea;
240240
const { instance } = useChartContext();
241-
const isClient = useIsClient();
241+
const isHydrated = useIsHydrated();
242242

243243
const tickSize = disableTicks ? 4 : tickSizeProp;
244244

@@ -333,7 +333,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
333333
axisHeight - (label ? labelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP,
334334
);
335335

336-
const tickLabels = isClient
336+
const tickLabels = isHydrated
337337
? shortenLabels(visibleLabels, drawingArea, tickLabelsMaxHeight, axisTickLabelProps.style)
338338
: new Map(Array.from(visibleLabels).map((item) => [item, item.formattedValue]));
339339

Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use client';
22
import * as React from 'react';
33

4-
/** Returns true after this hook runs the client.
4+
/** Returns true after hydration is done on the client.
55
*
66
* Basically a implementation of Option 2 of this gist: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85#option-2-lazily-show-component-with-uselayouteffect. */
7-
export function useIsClient() {
8-
const [isClient, setIsClient] = React.useState(false);
7+
export function useIsHydrated() {
8+
const [isHydrated, setIsHydrated] = React.useState(false);
99

1010
React.useEffect(() => {
11-
setIsClient(true);
11+
setIsHydrated(true);
1212
}, []);
1313

14-
return isClient;
14+
return isHydrated;
1515
}

0 commit comments

Comments
 (0)