bloczjs / react-responsive

🔍 <Only /> displays some contents for particular screen sizes
22 stars 0 forks source link

BreakpointListener #7

Closed Ayc0 closed 5 years ago

Ayc0 commented 6 years ago
<BreakpointListener on="sm mdUp xsDown">
  {breakpoint => (
    <div>{breakpoint}</div>
  )}
</BreakpointListener>

In this example, breakpoint can only be 'sm', 'mdUp' or 'xsDown'

if two intervals are intersecting, it should throw an error

Ayc0 commented 6 years ago

V2:

<BreakpointsConsumer on="sm mdUp xsDown">
  {({ sm, mdUp, xsDown }) => (
    <div>{sm && 'sm'}</div>
    <div>{mdUp && 'mdUp'}</div>
    <div>{xsDown && 'xsDown'}</div>
  )}
</BreakpointsConsumer>

and the react 16.7 hook version:

const App = () => {
  const { sm, mdUp, xsDown } = useBreakpoints();
  return (
    <div>{sm && 'sm'}</div>
    <div>{mdUp && 'mdUp'}</div>
    <div>{xsDown && 'xsDown'}</div>
  )
}
Ayc0 commented 5 years ago

Solved with useOnly