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

useBreakpointIndex causes flickering #2159

Open
MuhammadJamaluddin opened this issue Mar 3, 2022 · 0 comments
Open

useBreakpointIndex causes flickering #2159

MuhammadJamaluddin opened this issue Mar 3, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@MuhammadJamaluddin
Copy link

MuhammadJamaluddin commented Mar 3, 2022

Describe the bug
When useResponsiveValue is called twice once in the skeleton screen & another time in the actual screen, it causes a flicker

Why this is happening?
cause we initially have const [value, setValue] = useState(defaultIndex); where defaultIndex is 0 & then setValue is triggered after the component renders resulting in this flicker effect... using useLayoutEffect mitigates this issue

Another potential solution (I personally prefer this one) is to remove defaultOptions & use window.matchMedia to define the initial state instead of hardcoding 0 which seems problematic

To Reproduce
call useResponsiveValue twice 🤷‍♂️ ... once in a skeleton screen & another tine in the actual screen

Expected behavior
It doesn't flicker

Screenshots
with useEffect

Screen.Recording.2022-03-03.at.3.32.37.PM.mov

with useLayoutEffect

Screen.Recording.2022-03-03.at.3.34.58.PM.mov
@lachlanjc lachlanjc added the bug Something isn't working label Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants