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
matchMedia doesn't seem to be working with mediaClassNames #125
Comments
@jdesherlia - mind pasting a snipped of code for what you're trying to do? |
Feel free to reopen if this is still an issue |
Sorry @damassi got sidetracked for a while and this was an issue but not a blocker. It has since popped up again, and im more concerned that its just causing an oversized DOM. When I do something like the below, the content is never removed from the DOM when the breakpoint isn't matched:
Here is a screenshot fo this component on a desktop resolution. As you can see the class names get added and successfully hide the content, but its still rendered to the DOM: |
To confirm, do you have your root component wrapped in a context provider as seen here? |
Yes. We are using Gatsby so we wrap our app in gatsby-ssr.js and gatsby-browser.js like this:
I can also confirm that if I don't render a function inside a media component but instead allow it to generate the fresnal div, it does correctly render only the content for the matching browser size. I think the major difference is the presence of the |
You’re not utilizing the second render-prop parameter described here ( |
@alloy just had a chance to try this. That worked a treat, thanks! Went through and updated my whole app. I imagine this will help with our lighthouse score a bit. At least the part about excessive DOM size. :-) Have a great one, and thanks for the awesome package! |
Thanks for verifying, I’ve created a PR to expand the README doc #151 |
Hey All,
When trying to use the method described for passing
mediaClassNames
to my own components in order to avoid the extra div, it seems that all content is always present. I was under the impression that an eventListener and call to matchMedia should be selectively rendering only the matching components after rehydration. Is this a bug or am I mistaken as to how this should be working?Also, I can't seem to understand how the onlyMatch prop works. Any clarity you can provide there?
Thanks,
-Josh-
The text was updated successfully, but these errors were encountered: