Skip to content

Instantly share code, notes, and snippets.

@icyJoseph
Last active June 15, 2018 06:28
Show Gist options
  • Save icyJoseph/3afe4414d1f509dc6a2e354f933b9b48 to your computer and use it in GitHub Desktop.
Save icyJoseph/3afe4414d1f509dc6a2e354f933b9b48 to your computer and use it in GitHub Desktop.
React Media using a curried function to manage responsive content.
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