Skip to content

Commit d7ef80a

Browse files
chore: use react-intersection-observer in docs to improve perf (#3985)
* added react-intersection-observer module * moved react-intersection-observer to devDependencies. * implemented react intersection observer in docs component examples. * added observer * remove react-visibility-sensor * remove closure Co-authored-by: Oleksandr Fediashov <[email protected]>
1 parent ee9a7c7 commit d7ef80a

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

docs/src/components/ComponentDoc/ComponentExample/ComponentExample.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import cx from 'classnames'
33
import copyToClipboard from 'copy-to-clipboard'
44
import PropTypes from 'prop-types'
55
import React, { Component } from 'react'
6-
import VisibilitySensor from 'react-visibility-sensor'
6+
import { InView } from 'react-intersection-observer'
7+
78
import { Checkbox, Grid, Label } from 'semantic-ui-react'
89

910
import { examplePathToHash, scrollToAnchor } from 'docs/src/utils'
@@ -168,11 +169,7 @@ class ComponentExample extends Component {
168169
} = this.state
169170

170171
return (
171-
<VisibilitySensor
172-
delayedCall={!wasEverVisible}
173-
partialVisibility
174-
onChange={this.handleVisibility}
175-
>
172+
<InView onChange={this.handleVisibility}>
176173
<div id={anchorName} style={{ marginTop: '1rem' }}>
177174
<Grid className={cx('docs-example', showCode && 'active')} padded='vertically'>
178175
<Grid.Row columns='equal'>
@@ -224,7 +221,7 @@ class ComponentExample extends Component {
224221
{isActiveHash && <CarbonAdNative inverted={showCode} />}
225222
</Grid>
226223
</div>
227-
</VisibilitySensor>
224+
</InView>
228225
)
229226
}
230227
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@
157157
"react-docgen": "^4.1.0",
158158
"react-dom": "^16.9.0",
159159
"react-hot-loader": "^4.12.11",
160+
"react-intersection-observer": "^8.26.2",
160161
"react-router": "^5.0.0",
161162
"react-router-dom": "^5.0.0",
162163
"react-source-render": "^3.0.0-5",
163164
"react-static": "^5.9.7",
164165
"react-static-routes": "^1.0.0",
165166
"react-test-renderer": "^16.9.0",
166167
"react-universal-component": "^3.0.3",
167-
"react-visibility-sensor": "^5.0.2",
168168
"rimraf": "^2.6.3",
169169
"satisfied": "^1.1.2",
170170
"semantic-ui-css": "^2.4.1",

yarn.lock

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10041,6 +10041,13 @@ react-hot-loader@^4, react-hot-loader@^4.12.11:
1004110041
shallowequal "^1.1.0"
1004210042
source-map "^0.7.3"
1004310043

10044+
react-intersection-observer@^8.26.2:
10045+
version "8.26.2"
10046+
resolved "https://registry.yarnpkg.com/react-intersection-observer/-/react-intersection-observer-8.26.2.tgz#0562ff0c06b2b10e809190c2fa9b6ded656e6e16"
10047+
integrity sha512-GmSjLNK+oV7kS+BHfrJSaA4wF61ELA33gizKHmN+tk59UT6/aW8kkqvlrFGPwxGoaIzLKS2evfG5fgkw5MIIsg==
10048+
dependencies:
10049+
tiny-invariant "^1.1.0"
10050+
1004410051
react-is@^16.6.0, react-is@^16.6.3, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6, react-is@^16.9.0:
1004510052
version "16.9.0"
1004610053
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb"
@@ -10208,13 +10215,6 @@ react-universal-component@^2.8.1, react-universal-component@^3.0.3:
1020810215
hoist-non-react-statics "^2.2.1"
1020910216
prop-types "^15.5.10"
1021010217

10211-
react-visibility-sensor@^5.0.2:
10212-
version "5.0.2"
10213-
resolved "https://registry.yarnpkg.com/react-visibility-sensor/-/react-visibility-sensor-5.0.2.tgz#e360fff81572cb3a2a9fd680484447a9da09a55d"
10214-
integrity sha512-7+1lr7oQOO2vKr5u/uxoDGFWAAy7lsDy2aJU3Zy1/OymI+TRqOBk8m2L8YE1B0UyfCDWxVAWO+aifVGqNOvqeQ==
10215-
dependencies:
10216-
prop-types "^15.6.2"
10217-
1021810218
react@^16, react@^16.9.0:
1021910219
version "16.9.0"
1022010220
resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa"
@@ -11850,6 +11850,11 @@ tiny-invariant@^1.0.2:
1185011850
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.0.3.tgz#91efaaa0269ccb6271f0296aeedb05fc3e067b7a"
1185111851
integrity sha512-ytQx8T4DL8PjlX53yYzcIC0WhIZbpR0p1qcYjw2pHu3w6UtgWwFJQ/02cnhOnBBhlFx/edUIfcagCaQSe3KMWg==
1185211852

11853+
tiny-invariant@^1.1.0:
11854+
version "1.1.0"
11855+
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.1.0.tgz#634c5f8efdc27714b7f386c35e6760991d230875"
11856+
integrity sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==
11857+
1185311858
tiny-warning@^1.0.0:
1185411859
version "1.0.2"
1185511860
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.2.tgz#1dfae771ee1a04396bdfde27a3adcebc6b648b28"

0 commit comments

Comments
 (0)