Skip to content

Why isn't the breakpoints and currentBreakPoints logic within the Media component? #11

Open
@joetidee

Description

@joetidee

Is there any reason why this package isn't written so that it can be used like this:

<Media breakpoint="mobile">
  ...
</Media>
<Media breakpoint="desktop">
  ...
</Media>

So that the children are conditionally rendered?

I'm a little confused by your render props example in the readme file, should it be:

import { Media } from 'react-breakpoints'

class Navigation extends React.Component {
  render() {
    return (
      <Media render={({ breakpoints, currentBreakpoint }) =>
          breakpoints[currentBreakpoint] > breakpoints.desktop ? (
            <DesktopNavigation />
          ) : (
            <TouchNavigation />
          )
        }
      />
    )
  }
}

export default Navigation

As surely the breakpoints are captured in the Media component using context and currentBreakpoint is calculated by Media?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions