Skip to content

Commit 294ab83

Browse files
author
Tasveer Singh
committed
Update README with @loadable/component
1 parent a7c17e3 commit 294ab83

1 file changed

Lines changed: 25 additions & 29 deletions

File tree

README.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
# `react-loadable-visibility`
22

3-
> A wrapper around [react-loadable](https://github.com/thejameskyle/react-loadable) and [loadable-components](https://github.com/smooth-code/loadable-components), only loading imports that are visible on the page.
3+
> A wrapper around [react-loadable](https://github.com/thejameskyle/react-loadable) and [@loadable/component](https://github.com/smooth-code/loadable-components), only loading imports that are visible on the page.
44
5-
[![Build Status](https://travis-ci.org/stratiformltd/react-loadable-visibility.svg?branch=master)](https://travis-ci.org/stratiformltd/react-loadable-visibility)
5+
[![npm version](https://badge.fury.io/js/react-loadable-visibility.svg)](https://badge.fury.io/js/react-loadable-visibility) [![Build Status](https://travis-ci.org/stratiformltd/react-loadable-visibility.svg?branch=master)](https://travis-ci.org/stratiformltd/react-loadable-visibility)
66

77
## Example using `react-loadable`
88

99
```js
10-
import LoadableVisibility from 'react-loadable-visibility/react-loadable'
11-
import Loading from './my-loading-component'
10+
import LoadableVisibility from "react-loadable-visibility/react-loadable";
11+
import Loading from "./my-loading-component";
1212

1313
const LoadableComponent = LoadableVisibility({
14-
loader: () => import('./my-component'),
15-
loading: Loading,
16-
})
17-
18-
export default class App extends React.Component {
19-
render() {
20-
return <LoadableComponent />
21-
}
14+
loader: () => import("./my-component"),
15+
loading: Loading
16+
});
17+
18+
export default function App() {
19+
return <LoadableComponent />;
2220
}
2321
```
2422

25-
## Example using `loadable-components`
23+
## Example using `@loadable/component`
2624

2725
```js
28-
import loadableVisibility from 'react-loadable-visibility/loadable-components'
29-
import Loading from './my-loading-component'
26+
import loadableVisibility from "react-loadable-visibility/loadable-components";
27+
import Loading from "./my-loading-component";
3028

31-
const LoadableComponent = loadableVisibility(() => import('./my-component'), {
32-
LoadingComponent: Loading,
33-
})
29+
const LoadableComponent = loadableVisibility(() => import("./my-component"), {
30+
fallback: Loading
31+
});
3432

35-
export default class App extends React.Component {
36-
render() {
37-
return <LoadableComponent />
38-
}
33+
export default function App() {
34+
return <LoadableComponent />;
3935
}
4036
```
4137

@@ -44,25 +40,25 @@ export default class App extends React.Component {
4440
The API is exactly the same as the original library. Please refer to their documentation:
4541

4642
- [react-loadable documentation](https://github.com/thejameskyle/react-loadable#guide)
47-
- [loadable-components documentation](https://github.com/smooth-code/loadable-components#getting-started)
43+
- [@loadable/component documentation](https://github.com/smooth-code/loadable-components#docs)
4844

49-
Note that you'll need to have `react-loadable` or `loadable-components` in your `package.json`.
45+
Note that you'll need to have `react-loadable` or `@loadable/component` in your `package.json`.
5046

5147
# How does this work?
5248

5349
It's in essence a wrapper around `loadable` libraries with hooks into an [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to inform us of when a given element is in the viewport.
5450

5551
Therefore, it will only function in [browsers that have the `IntersectionObserver` API](http://caniuse.com/#feat=intersectionobserver).
5652

57-
[A polyfill for `IntersectionObserver` is available](https://github.com/WICG/IntersectionObserver/tree/gh-pages/polyfill) however I am skeptical of its performance but have not tested it fully to offer a recommendation here. If you have any comments about this, feel free to open a PR and adjust this README!
53+
[A polyfill for `IntersectionObserver` is available](https://github.com/w3c/IntersectionObserver/tree/master/polyfill) however I am skeptical of its performance but have not tested it fully to offer a recommendation here. If you have any comments about this, feel free to open a PR and adjust this README!
5854

59-
If you choose the use the polyfill, you can load it via a [polyfill.io](https://cdn.polyfill.io/v2/docs/) script - `<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>`
55+
If you choose the use the polyfill, you can load it via a [polyfill.io](https://cdn.polyfill.io/v3/) script - `<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver%2CIntersectionObserverEntry"></script>`
6056

61-
Otherwise if the `IntersectionObserver` API is not available, we will revert back to just using `react-loadable` or `loadable-components` itself.
57+
Otherwise if the `IntersectionObserver` API is not available, we will revert back to just using `react-loadable` or `@loadable/component` itself.
6258

6359
# Why do I want this?
6460

65-
`react-loadable` and `loadable-components` are fantastic higher level components to load additional modules once they are mounted on your page. It's great for keeping your bundle size small and pulling in a larger payload when the required components are part of your tree.
61+
`react-loadable` and `@loadable/component` are fantastic higher level components to load additional modules once they are mounted on your page. It's great for keeping your bundle size small and pulling in a larger payload when the required components are part of your tree.
6662

6763
However it will not account for the content that's currently visible on your page, and only load what's actually visible to the end user. If you have a long page and are loading the entire content of that page for the user, even though they may only be able to see the content [above the fold](https://www.optimizely.com/optimization-glossary/above-the-fold/), it can be wasteful and especially detrimental in a mobile context.
6864

@@ -81,4 +77,4 @@ Have a look at the [GitHub contributors page](https://github.com/stratiformltd/r
8177

8278
`react-loadable-visibility` may be redistributed according to the [BSD 3-Clause License](LICENSE).
8379

84-
Copyright 2018, Stratiform Limited.
80+
Copyright 2019, Stratiform Limited.

0 commit comments

Comments
 (0)