Skip to content

Commit 67110a8

Browse files
authored
Merge pull request #9 from braposo/add-lazy
Add lazy option to HOC function
2 parents ed587e7 + 6af85cd commit 67110a8

File tree

6 files changed

+1958
-24
lines changed

6 files changed

+1958
-24
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a React component that provides an API to the [scrollMonitor](https://gi
44

55
It adds all the boolean properties from a watcher to `this.props` and takes all the method properties as properties.
66

7-
Scrollmonitor-react is two higher order components. They're functions that your pass an original component and receive a new component that adds functionality to the original.
7+
Scrollmonitor-react is two higher order components. They're functions that you pass an original component and receive a new component that adds functionality to the original.
88

99
## Basic Usage
1010

@@ -40,7 +40,7 @@ import React from 'react';
4040
import MyWatchedComponent from './the/example/above';
4141

4242
export default MyParentComponent extends React.Component {
43-
43+
4444
receiveStateChange (watcher) {
4545
console.log('state changed!', watcher)
4646
}
@@ -51,6 +51,10 @@ export default MyParentComponent extends React.Component {
5151
}
5252
```
5353

54+
### Avoid starting the watcher automatically
55+
56+
By default the watcher is started on every enhanced component, but there can be situations where you want to start the watcher later so you can set the prop `autoStart` to `false` to avoid starting the watcher automatically.
57+
5458
## API
5559

5660
### `this.props` provided to your component
@@ -61,13 +65,16 @@ export default MyParentComponent extends React.Component {
6165
* `this.props.isBelowViewport` - true if any part of the element is below the viewport.
6266
* `this.props.lockWatcher()` - locks the watcher letting you move the element but watch the same place. See the scrollMonitor's documentation for more info.
6367
* `this.props.unlockWatcher()` - unlocks the watcher.
68+
* `this.props.startWatcher()` - starts the watcher if it's not running
69+
* `this.props.stopWatcher()` - stops the watcher if it's running
6470

6571
_1. If the element is larger than the viewport `isFullyInViewport` is true when the element spans the entire viewport._
6672

67-
### Propeties you provide to the component
73+
### Properties you provide to the component
6874

6975
```javascript
7076
<MyWatchedComponent
77+
autoStart={true|false} // Decide if watcher should start when component is mounted. Default: true
7178
stateChange={() => {}} // Called when any part of the state changes.
7279
visibilityChange={() => {}} // when the element partially enters or fully exits the viewport.
7380
enterViewport={() => {}} // when the element enters the viewport.
@@ -79,7 +86,7 @@ _1. If the element is larger than the viewport `isFullyInViewport` is true when
7986
</MyWatchedComponent>
8087
```
8188

82-
_1. If the element is larger than the viewport `fullyEnterViewport` will be triggered when the element spans the entire viewport._
89+
_1. If the element is larger than the viewport `fullyEnterViewport` will be triggered when the element spans the entire viewport._
8390
_2. If the element is larger than the viewport `partiallyExitViewport` will be triggered when the element no longer spans the entire viewport._
8491

8592
## Scroll Containers

dist/index.js

Lines changed: 32 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)