React Web Breakpoints
Responsive design based on breakpoints demo
Install
# with npm $ npm install react-web-breakpoints --save# or with yarn $ yarn add react-web-breakpoints
Usage
;
BreakpointsProvider
;;;; const mountNode = document;ReactDOM;
With Hooks - useBreakpoints (it returns current breakpoint e.g. lg)
;; const App = { const media = ; return <h1>Hello name - Screen media</h1>;}; ;
With HOC - withBreakpoints (wrapped component i.e. App receives new props media
)
;; const App = { return <h1>Hello name - Screen media</h1>;}; App;
With BreakShowAt - renders its children when current breakpoint (say lg) match with its props (i.e. md and lg)
;; const App = { return <BreakShowAt md lg> <div>This content shows for md and lg screens</div> </BreakShowAt> ;}; ;
BreakpointsProvider - Props
Name | Type | Default | Description |
---|---|---|---|
breakpoints | object | { sm: 0, md: 768, lg: 1024 } | By default 0 < sm < 768, 768 < md < 1024, 1024 < lg. Object structure { [string]: [number], ... } e.g. { mobile: 0, tablet: 768, desktop: 1024 } |
defaultBreakpoint | string | null | By default null. For initial render or if window width does not fall under any range mentioned in breakpoints props. |
Source Code Run
Install the dependencies and devDependencies and start the server.
$ git clone git@github.com:sagarpanda/react-web-breakpoints.git$ cd react-web-breakpoints$ npm install$ npm start