Skip to content

Difference to react-responsive? #70

New issue

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

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

Already on GitHub? # to your account

Closed
FBosler opened this issue Jul 19, 2017 · 1 comment
Closed

Difference to react-responsive? #70

FBosler opened this issue Jul 19, 2017 · 1 comment

Comments

@FBosler
Copy link

FBosler commented Jul 19, 2017

Not really an issue but something that bothers me (and I think other people as well). When doing a quick search for responsiveness in react react-media and react-responsive (https://github.com/contra/react-responsive) come up. So I checked both github pages out, and from what I can tell both libraries look rather similar in what and how they do it.

So I think it would be worthwhile to include some information on what the differences are and for which use cases react-media is better ....

@mjackson
Copy link
Member

react-responsive works like an if statement. You create all of the elements inside their <MediaQuery> component, and then it decides whether or not it'll actually render those children to the page. In other words, like this:

<MediaQuery>
  {/* These elements are _always_ created */}
  {/* Even when the media query doesn't match :( */}
  <p />
</MediaQuery>

However, when the media query does not match you still create all of those elements, but essentially discard them when none of them are rendered to the page.

In contrast, react-media takes a different approach by using a render prop to conditionally create elements only when the media query matches, which saves you creating all those element objects when it doesn't, so it's a lot more efficient.

<Media render={() => (
  <div>
    {/* These elements are only created when the query matches! */}
    <p />
  </div>
)}/>

Hope that helps!

@ReactTraining ReactTraining deleted a comment from yocontra Dec 1, 2018
@ReactTraining ReactTraining deleted a comment from ken0x0a Dec 1, 2018
@ReactTraining ReactTraining locked and limited conversation to collaborators Dec 1, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Development

No branches or pull requests

2 participants