Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ var React = require('react')
var useState = React.useState
var useCallback = React.useCallback
var useLayoutEffect = React.useLayoutEffect
var useEffect = React.useEffect
/**
* To properly measure. we need useLayoutEffect in the client but it generates a warning in the console
* since it has no effect when it runs on the server. This is to work around it.
* We've used this implementation: https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts
*
* See this issue for more details: https://github.com/rehooks/component-size/issues/32
*/
var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect

function getSize(el) {
if (!el) {
Expand Down Expand Up @@ -32,7 +41,7 @@ function useComponentSize(ref) {
[ref]
)

useLayoutEffect(
useIsomorphicLayoutEffect(
function() {
if (!ref.current) {
return
Expand Down