dahliacreative/react-device-breakpoints

View on GitHub
src/Consumer/index.js

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react'
import { Consumer } from '../Context'

const generateComponents = device => {
    const components = {}
    Object.entries(device).forEach(([key, matches]) => {
        components[key] = ({ children }) => {
            return <>
                {matches && children}
            </>
        }
    })
    return components
}

const Media = ({ children }) => (
    <Consumer>
        {device => children(device, generateComponents(device))}
    </Consumer>
)

export default Media