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
|**children**| Func/Node || false | Children should be either a function or a node |
57
+
|**render**| ({inView, ref}) => Node || false | Render prop allowing you to control the view. |
58
+
|**root**| HTMLElement || false | The HTMLElement that is used as the viewport for checking visibility of the target. Defaults to the browser viewport if not specified or if null. |
59
+
|**rootId**| String || false | Unique identifier for the root element - This is used to identify the IntersectionObserver instance, so it can be reused. If you defined a root element, without adding an id, it will create a new instance for all components. |
60
+
|**rootMargin**| String | '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
61
+
|**tag**| String | 'div' | false | Element tag to use for the wrapping component |
62
+
|**threshold**| Number | 0 | false | Number between 0 and 1 indicating the the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
63
+
|**triggerOnce**| Bool | false | false | Only trigger this method once |
64
+
|**onChange**| Func || false | Call this function whenever the in view state changes |
65
+
66
+
## Examples
67
+
68
+
### Child as function
69
+
70
+
The default way to use the `Observer`, is to pass a function as the child. It
71
+
will be called whenever the state changes, with the new value of `inView`.
72
+
By default it will render inside a `<div>`, but you can change the element by setting `tag` to the HTMLElement you need.
|**children**| func/node || true | Children should be either a function or a node |
109
-
|**root**| HTMLElement || false | The HTMLElement that is used as the viewport for checking visibility of the target. Defaults to the browser viewport if not specified or if null. |
110
-
|**rootId**| String || false | Unique identifier for the root element - This is used to identify the IntersectionObserver instance, so it can be reused. If you defined a root element, without adding an id, it will create a new instance for all components. |
111
-
|**rootMargin**| String | '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
112
-
|**tag**| String | 'div' | false | Element tag to use for the wrapping component |
113
-
|**threshold**| Number | 0 | false | Number between 0 and 1 indicating the the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
114
-
|**triggerOnce**| Bool | false | false | Only trigger this method once |
115
-
|**onChange**| Func || false | Call this function whenever the in view state changes |
/** Render prop boolean indicating inView state */
13
-
render?: (inView: boolean)=>React.Node,
14
+
render?: ({
15
+
inView: boolean,
16
+
ref: (node: ?HTMLElement)=>void,
17
+
})=>React.Node,
14
18
/** Number between 0 and 1 indicating the the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. */
15
19
threshold?: number|Array<number>,
16
20
/** The HTMLElement that is used as the viewport for checking visibility of the target. Defaults to the browser viewport if not specified or if null.*/
@@ -22,8 +26,6 @@ type Props = {
22
26
rootId?: string,
23
27
/** Call this function whenever the in view state changes */
24
28
onChange?: (inView: boolean)=>void,
25
-
/** Get a reference to the the inner DOM node */
26
-
innerRef?: Function,
27
29
}
28
30
29
31
typeState={
@@ -50,6 +52,15 @@ class Observer extends React.Component<Props, State> {
50
52
inView: false,
51
53
}
52
54
55
+
componentDidMount(){
56
+
if(typeofthis.props.render==='function'){
57
+
invariant(
58
+
this.node,
59
+
`react-intersection-observer: No DOM node found. Make sure you forward "ref" to the root DOM element you want to observe, when using render prop.`,
0 commit comments