Last active
June 15, 2018 06:28
-
-
Save icyJoseph/3afe4414d1f509dc6a2e354f933b9b48 to your computer and use it in GitHub Desktop.
React Media using a curried function to manage responsive content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Media from 'react-media'; | |
// functional helper | |
const curry = f => a => (...b) => f(a,...b) | |
const Mobile = ({ title }) => <div>{title} Mobile</div>; | |
const Desktop = ({title}) => <div>{title} Desktop</div>; | |
const MediaContent = (props, matches) => { | |
matches => (matches ? <Mobile {...props} /> : <Desktop {...props} />); | |
}; | |
const Responsive = ({ ...props }) => ( | |
<Media query={{ maxWidth: 1023 }}> | |
{curry(MediaContent)(props)} | |
</Media> | |
); | |
export default Responsive; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment