-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
hook: useMediaQuerysupport: questionCommunity support but can be turned into an improvement.Community support but can be turned into an improvement.
Description
At pageload, useMediaQuery will return false-negative if it was actually true, instantly forcing a re-render and correctly returning true.
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
There are two ways to formulate it:
- At pageload,
useMediaQueryreturnsfalsefirst. Then, if they actually weretruefrom the very beggining, they will force instant re-render, returningtrue. - At pageload,
useMediaQuerywill return false-negative if it was actuallytrue, instantly forcing a re-render correctly returningtrueafterwards.
That leads to potential double-renders at page-load, impacting performance.
Expected Behavior 🤔
useMediaQuery to return correct value with first time.
Steps to Reproduce 🕹
https://codesandbox.io/s/lively-sky-gl983
Context 🔦
I have a wrapper component that renders either A or B subcomponent based on a media querry, where both A and B are both rather heavy. With this problem, I can't ensure that I will render the right one first time, without wasting time rendering the other.
Your Environment 🌎
See versions on https://codesandbox.io
Metadata
Metadata
Assignees
Labels
hook: useMediaQuerysupport: questionCommunity support but can be turned into an improvement.Community support but can be turned into an improvement.