Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Use useLayoutEffect instead of useEffect #72

Closed
jamesmoss opened this issue Dec 19, 2021 · 2 comments · Fixed by #77
Closed

Use useLayoutEffect instead of useEffect #72

jamesmoss opened this issue Dec 19, 2021 · 2 comments · Fixed by #77
Assignees

Comments

@jamesmoss
Copy link

This change will prevent some flickering that I've seen, Kent describes it well here https://kentcdodds.com/blog/useeffect-vs-uselayouteffect:

However, if your effect is mutating the DOM (via a DOM node ref) and the DOM mutation will change the appearance of the DOM node between the time that it is rendered and your effect mutates it, then you don't want to use useEffect. You'll want to use useLayoutEffect. Otherwise the user could see a flicker when your DOM mutations take effect.

I'd say this is the perfect use case.

@rpearce rpearce self-assigned this Dec 20, 2021
@rpearce
Copy link
Owner

rpearce commented Dec 20, 2021

@jamesmoss Thank you for bringing this up. I'll try it out with this and see how it goes

@rpearce
Copy link
Owner

rpearce commented Dec 21, 2021

Checks out! I've got this queued up for the next patch-level release, and I've added you to the all contributors list in the README! Thanks for your time here.

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

Successfully merging a pull request may close this issue.

2 participants