Skip to content

Commit fef2a32

Browse files
committed
Move Context
1 parent f81d245 commit fef2a32

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

docs/api.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Common usage:
44

55
- [`<Provider>`](#provider)
66
- [`<Observe>`](#observe)
7-
- [`useBreakpoints()`](#usebreakpoints)
87

98
Advanced usage:
109

11-
- [`<Context>`](#context)
10+
- [`useBreakpoints()`](#usebreakpoints)
1211
- [`useResizeObserver()`](#useresizeobserver)
1312
- [`useResizeObserverEntry()`](#useresizeobserverentry)
13+
- [`<Context>`](#context)
1414

1515
---
1616

@@ -193,6 +193,8 @@ const MyObservingComponent = () => (
193193

194194
# `useBreakpoints()`
195195

196+
⚠️ **Advanced usage** — This hook is used internally in [`<Observe>`](#observe) to enable the use of the optional `breakpoints` prop.
197+
196198
Components inside an "[`<Observe>`](#observe) scope" have access to its observations. The observed element's sizes are available on a [context](#context) via the `useBreakpoints()` hook.
197199

198200
The hook takes an `options` object as its first argument, which must include a `widths` or `heights` key (or both) with an object as its value. That object must have a shape of numbers as keys, and a value of any type. The value you set here is what will eventually be returned by `useBreakpoints()`.
@@ -376,44 +378,6 @@ const MyResponsiveComponent = () => {
376378

377379
---
378380

379-
# `<Context>`
380-
381-
⚠️ **Advanced usage** — This React context is used internally by [`useBreakpoints()`](#usebreakpoints). You may use this context with `React.useContext()` to access the information stored in the context provider, which is typically a `ResizeObserverEntry` set internally by [`<Observe>`](#observe).
382-
383-
## Reference guide
384-
385-
```javascript
386-
<Context.Provider value={ResizeObserverEntry}>
387-
```
388-
389-
## Usage
390-
391-
`parent.js`
392-
393-
```javascript
394-
import { Context } from '@envato/react-breakpoints';
395-
396-
<Context.Provider value={myResizeObserverEntry}>
397-
/* children with access to `myResizeObserverEntry` */
398-
</Context.Provider>;
399-
```
400-
401-
`child.js`
402-
403-
```javascript
404-
import { useContext } from 'react';
405-
import { Context } from '@envato/react-breakpoints';
406-
407-
const MyChildComponent = () => {
408-
const myResizeObserverEntry = useContext(Context);
409-
/* ... */
410-
};
411-
```
412-
413-
⚠️ **Hint** — Instead of manually implementing the `child.js` portion as above, you may want to use [`useResizeObserverEntry()`](#useresizeobserverentry) instead.
414-
415-
---
416-
417381
# `useResizeObserver()`
418382

419383
⚠️ **Advanced usage** — This hook is used internally in [`<Observe>`](#observe) to:
@@ -562,3 +526,41 @@ const MyResponsiveComponent = () => {
562526
```
563527

564528
⚠️ **Hint** — You probably don't need this hook, because [`useBreakpoints()`](#usebreakpoints) abstracts the above implementation away for your convenience. You'll likely only need this hook if you need a property from `ResizeObserverEntry` which is not `contentRect` or one of `box`'s options.
529+
530+
---
531+
532+
# `<Context>`
533+
534+
⚠️ **Internal usage, you probably don't need this!** — This React context is used internally by [`useBreakpoints()`](#usebreakpoints). You may use this context with `React.useContext()` to access the information stored in the context provider, which is typically a `ResizeObserverEntry` set internally by [`<Observe>`](#observe).
535+
536+
## Reference guide
537+
538+
```javascript
539+
<Context.Provider value={ResizeObserverEntry}>
540+
```
541+
542+
## Usage
543+
544+
`parent.js`
545+
546+
```javascript
547+
import { Context } from '@envato/react-breakpoints';
548+
549+
<Context.Provider value={myResizeObserverEntry}>
550+
/* children with access to `myResizeObserverEntry` */
551+
</Context.Provider>;
552+
```
553+
554+
`child.js`
555+
556+
```javascript
557+
import { useContext } from 'react';
558+
import { Context } from '@envato/react-breakpoints';
559+
560+
const MyChildComponent = () => {
561+
const myResizeObserverEntry = useContext(Context);
562+
/* ... */
563+
};
564+
```
565+
566+
⚠️ **Hint** — Instead of manually implementing the `child.js` portion as above, you may want to use [`useResizeObserverEntry()`](#useresizeobserverentry) instead.

0 commit comments

Comments
 (0)