You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73-62Lines changed: 73 additions & 62 deletions
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,18 @@
4
4
5
5
This library solves the problem that CSS media queries alone could not solve. Sometimes you want to create an application that looks a certain way on desktop and a certain way on mobile. Sometimes the components look too different for you to be able to just change the CSS, you have to make one component for desktop and another for mobile. This is bad, because the JavaScript for the hidden component is still running in the background even though you are not seeing it.
6
6
7
-
This library solves that.
8
-
9
7
`react-breakpoints` allows you to use the viewport width to load different components, opening up for building more complex responsive applications without suffering the performance problems of hidden desktop components on your mobile site and vice versa.
10
8
11
-
This library is not dependent on Redux, see documentation for instructions on how to use.
9
+
Version 2.0.0 was rewrite with the new context API that came in React `16.3.0`. A polyfill for older React versions is included in the library, so it is backwards compatible with `15.x.x` and `16.x.x`. However, version 4.0.0 will no longer support `15.x.x`.
12
10
13
-
Version 2.0.0 is a rewrite with the new context API that came in React `16.3.0`. A polyfill for older React versions is included in the library, so it is backwards compatible with `15.x.x` and `16.x.x`.
11
+
Version 3.0.0 introduced `<Media>`with `renderProps` an alternative to the `withBreakpoints` HOC.
14
12
15
13
## Roadmap
16
14
17
-
**VERSION 3.0.0**
18
-
-[ ] Test that `guessedBreakpoint` prop from server side rendering works, make changes if needed.
19
-
-[ ] Example project
20
-
-[ ]`debounceOptions` object passdown if needed.
15
+
*[ ]`debounceOptions` object passdown if needed.
21
16
22
17
## Installation
18
+
23
19
`npm install --save react-breakpoints`
24
20
25
21
## Usage
@@ -44,65 +40,92 @@ const breakpoints = {
44
40
ReactDOM.render(
45
41
<ReactBreakpoints breakpoints={breakpoints}>
46
42
<App />
47
-
</ReactBreakpoints>,
48
-
document.getElementById('root')
43
+
</ReactBreakpoints>,
44
+
document.getElementById('root'),
49
45
)
50
46
```
51
47
52
48
## Inside your components
53
49
54
-
When you want access to the current screen width inside a component you import the `withBreakpoints` function, wrapping your component when you export it. This will give you access to `props.screenWidth` which updates whenever you resize your window or your device orientation changes and `props.breakpoints` which is the original object which you supplied to the `ReactBreakpoints` component.
50
+
When you want access to the current screen width inside a component you import the `withBreakpoints` function, wrapping your component when you export it. This will give you access to `props.currentBreakpoint` which updates whenever you resize your window to the point where it hits a new breakpoint, or your device orientation changes. It also adds `props.breakpoints` which is the original object which you supplied to the `ReactBreakpoints` component, so you can make comparisons with `props.currentBreakpoint`.
By default, this library does NOT debounce the `resize` listener. However, by passing the `debounceResize` prop to the `ReactBreakpoints` component it will be enabled with a default delay.
152
162
153
163
```js
@@ -163,6 +173,7 @@ ReactDOM.render(
163
173
```
164
174
165
175
### `debounceDelay: number[ms]` option
176
+
166
177
Set a custom delay in milliseconds for how the length of the debounce wait.
167
178
168
179
```js
@@ -179,10 +190,10 @@ ReactDOM.render(
179
190
```
180
191
181
192
### `defaultBreakpoint: number` option
182
-
In case you always want to default to a certain breakpoint, say you're building a mobile-only application - you can pass the mobile breakpoint here.
183
193
184
-
```js
194
+
In case you always want to default to a certain breakpoint.
0 commit comments