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

Media component only works when passing children prop rather than render prop #63

Closed
morsdyce opened this issue Dec 16, 2017 · 7 comments
Labels

Comments

@morsdyce
Copy link

The following does not work:

import { Media } from 'react-fns'

const Example = () =>
  <Media
    query="(min-width: 1000px)"
    render={(match) =>
     <div>
        {match ? 'mobile' : 'desktop'}
     </div>
    }
  />

export default Example

but this does:

import { Media } from 'react-fns'

const Example = () =>
  <Media
    query="(min-width: 1000px)"
    children={(match) =>
     <div>
        {match ? 'mobile' : 'desktop'}
     </div>
    }
  />

export default Example
@macklinu
Copy link
Contributor

I was curious about this and could reproduce it on CodeSandbox:

image

@Gabri3l
Copy link

Gabri3l commented Jan 30, 2018

From my understanding this is actually expected behavior, directly form the react-media docs we have:

or the common case of "only render something when the media query matches", you can use a render prop that is only called if the query matches.

In the example from this issue, we are matching the else clause of the ternary operator so the render prop returns null. I suppose that for this library the render method doesn't behave as we would imagine (meaning to just render what is provided). We can either create a fork of react-media with these changes (I am happy to do it) or submit a PR for react-media but then I don't know if that would break the old behavior.

@marzelin
Copy link

marzelin commented May 6, 2018

Please update the example in the docs as shown by @morsdyce. I've lost 10 mins on investigating why this doesn't work as expected.

@streamich
Copy link

Consider using react-universal-interface to avoid such issues.

@artivilla
Copy link

@Gabri3l the library doesn't work as intended, correct? I'd rather this moves to a breaking change.

@stale
Copy link

stale bot commented Aug 25, 2018

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

@stale stale bot added the stale label Aug 25, 2018
@stale
Copy link

stale bot commented Sep 1, 2018

Closed due to inactivity. Holler if this is a mistake, and we'll re-open it.

@stale stale bot closed this as completed Sep 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants