Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incosistent behavior #118

Open
hyoretsu opened this issue Apr 17, 2024 · 0 comments
Open

Incosistent behavior #118

hyoretsu opened this issue Apr 17, 2024 · 0 comments

Comments

@hyoretsu
Copy link

hyoretsu commented Apr 17, 2024

Long story short we have an array of div's with an useEffect that uses a Ref, divided into 4 columns using <ResponsiveMasonry />, but the first one doesn't work properly.

  const [isClamped, setIsClamped] = useState(false)
  const commentRef = useRef<HTMLParagraphElement>(null)

  useEffect(() => {
    if (commentRef.current?.scrollHeight! > commentRef.current?.clientHeight!) {
      setIsClamped(true)
    }
  }, [])
  const [isClamped, setIsClamped] = useState(false)
  const commentRef = useRef<HTMLParagraphElement>(null)

  useEffect(() => {
    setIsClamped(commentRef.current?.scrollHeight! > commentRef.current?.clientHeight!)
  }, [])

Both strategies should work, right? The ref starts as null, which doesn't set isClamped to true, but then it renders, updates the ref and changes isClamped to true. (In the second

Except it doesn't, only the three latter columns get re-rendered for some reason. When checking the profiler, it shows that it re-rendered because of hook 3 (hasMounted):

image

and that Masonry's columnCount prop also changed.

What actually happens is this (logging the result of that condition):
image

Using a hand-made masonry component fixes this problem without any changes to the component with the useEffect, so it's something in this lib.

In fact I was wrong when I said that the ref started as null, because it's defined from the get-go (when using this hand-made component):
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant