Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit 38af635

Browse files
committed
fix: avoid SSR warning on Text
1 parent c003e6b commit 38af635

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/shared/core/Text.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ function ellipsis({ lines = Infinity }) {
1717
`
1818
}
1919

20+
const isServer = typeof window === 'undefined'
21+
22+
function useUniversalLayoutEffect(callback, deps) {
23+
return isServer
24+
? React.useEffect(callback, deps)
25+
: React.useLayoutEffect(callback, deps)
26+
}
27+
2028
export const TEXT_VARIANTS = [
2129
'h1',
2230
'h2',
@@ -40,7 +48,7 @@ export const Text = createComponent({
4048
const As = asProp || (variantConfig && variantConfig.defaultAs) || 'span'
4149
const localRef = React.useRef()
4250
const [height, setHeight] = React.useState(null)
43-
React.useLayoutEffect(() => {
51+
useUniversalLayoutEffect(() => {
4452
if (!window.getComputedStyle || lines === Infinity) return
4553
const style = window.getComputedStyle(localRef.current)
4654
const lineHeight = parseInt(style.lineHeight, 10)

0 commit comments

Comments
 (0)