react-lazy-load
Advanced tools
Comparing version 3.1.14 to 4.0.0
{ | ||
"name": "react-lazy-load", | ||
"version": "3.1.14", | ||
"version": "4.0.0", | ||
"description": "Simple lazy loading component built with react", | ||
"main": "./lib/LazyLoad.js", | ||
"type": "module", | ||
"main": "./dist/LazyLoad.umd.cjs", | ||
"module": "./dist/LazyLoad.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/LazyLoad.js", | ||
"require": "./dist/LazyLoad.umd.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min", | ||
"build:lib": "babel src --out-dir lib", | ||
"build:umd": "webpack src/LazyLoad.jsx dist/LazyLoad.js --config webpack.config.development.js", | ||
"build:umd:min": "webpack src/LazyLoad.jsx dist/LazyLoad.min.js --config webpack.config.production.js", | ||
"build": "npx vite build", | ||
"clean": "rimraf lib dist", | ||
"lint": "eslint src/LazyLoad.jsx", | ||
"lint": "eslint src/LazyLoad.tsx", | ||
"prepublish": "npm run clean && npm run build", | ||
@@ -37,37 +43,28 @@ "test": "jest" | ||
"devDependencies": { | ||
"babel-cli": "^6.3.17", | ||
"babel-core": "^6.2.1", | ||
"babel-eslint": "^4.1.5", | ||
"babel-jest": "^12.0.2", | ||
"babel-loader": "^6.2.0", | ||
"babel-preset-es2015": "^6.1.18", | ||
"babel-preset-react": "^6.1.18", | ||
"babel-preset-stage-0": "^6.1.18", | ||
"eslint": "^1.8.0", | ||
"eslint-config-airbnb": "^0.1.0", | ||
"eslint-plugin-react": "^3.7.1", | ||
"jest-cli": "^12.0.2", | ||
"react": "^0.14.8", | ||
"react-addons-test-utils": "^0.14.8", | ||
"react-dom": "^0.14.8", | ||
"rimraf": "^2.4.4", | ||
"webpack": "^1.12.2" | ||
"@types/lodash": "^4.14.184", | ||
"@types/react": "^18.0.17", | ||
"@types/react-dom": "^18.0.6", | ||
"@typescript-eslint/eslint-plugin": "^5.34.0", | ||
"@typescript-eslint/parser": "^5.34.0", | ||
"eslint": "^8.22.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-import-resolver-typescript": "^3.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsx-a11y": "^6.6.1", | ||
"eslint-plugin-react": "^7.30.1", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rimraf": "^3.0.2" | ||
}, | ||
"dependencies": { | ||
"eventlistener": "0.0.1", | ||
"lodash.debounce": "^4.0.0", | ||
"lodash.throttle": "^4.0.0", | ||
"prop-types": "^15.5.8" | ||
"@vitejs/plugin-react": "^2.0.1", | ||
"typescript": "^4.7.4", | ||
"vite": "^3.0.9", | ||
"vite-plugin-dts": "^1.4.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^0.14.0 || ^15.0.0-0 || ^16.0.0 || ^17.0.0", | ||
"react-dom": "^0.14.0 || ^15.0.0-0 || ^16.0.0 || ^17.0.0" | ||
}, | ||
"jest": { | ||
"unmockedModulePathPatterns": [ | ||
"<rootDir>/node_modules/react/", | ||
"<rootDir>/node_modules/react-dom/", | ||
"<rootDir>/node_modules/react-addons-test-utils/" | ||
] | ||
"react": "^17.0.0 || ^18.0.0", | ||
"react-dom": "^17.0.0 || ^18.0.0" | ||
} | ||
} |
136
README.md
React Lazy Load Component | ||
========================= | ||
React Lazy Load is easy to use React component which helps you defer loading content in predictable way. It's fast, works in IE8+, 6KB minified and uses debounce function by default. You can also use component inside scrolling container, such as div with scrollbar. It will be found automatically. Check out an example. | ||
React Lazy Load is an easy-to-use React component which helps you defer loading content in predictable way. It's fast, You can also use component inside scrolling container, such as div with scrollbar. It will be found automatically. Check out an example. | ||
[![build status](https://img.shields.io/travis/loktar00/react-lazy-load.svg?style=flat-square)](https://travis-ci.org/loktar00/react-lazy-load) | ||
[![dependency status](https://david-dm.org/loktar00/react-lazy-load.svg?style=flat-square)](https://david-dm.org/loktar00/react-lazy-load) | ||
[![npm downloads](https://img.shields.io/npm/dm/react-lazy-load.svg?style=flat-square)](https://www.npmjs.com/package/react-lazy-load) | ||
## 4.0 Update | ||
Converted to work with React 18, and updated to use the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). | ||
### Breaking changes | ||
* No more debunce, or throttle options as they aren't needed | ||
* Removed individual offset props, offset can be used just like css margin, eg. `offset={'0px 10px 200px 0px'}` or `offset={100}` | ||
### Improvements | ||
Since we're now using the intersection observer we don't need to watch a user scroll, more importantly we don't have to manually calculate if a user can see the element or not. | ||
Also took this oppourtunity to convert over to TS. | ||
## Installation | ||
React Lazy Load requires **React 0.14 or later.** | ||
React Lazy Load requires **React 17 or later.** | ||
``` | ||
npm install --save react-lazy-load | ||
npm i -S react-lazy-load | ||
``` | ||
## Examples | ||
* [Basic](https://github.com/loktar00/react-lazy-load/tree/master/examples/basic) | ||
* [In Repo](https://github.com/loktar00/react-lazy-load/tree/master/examples/basic) | ||
## Usage | ||
## Examples | ||
### Basic Usage | ||
```jsx | ||
@@ -28,27 +39,46 @@ import React from 'react'; | ||
<div> | ||
Scroll to load images. | ||
<div className="filler" /> | ||
<LazyLoad height={762} offsetVertical={300}> | ||
<LazyLoad height={762}> | ||
<img src='http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg' /> | ||
</LazyLoad> | ||
<div className="filler" /> | ||
<LazyLoad height={683} offsetTop={200}> | ||
<img src='http://apod.nasa.gov/apod/image/1502/2015_02_20_conj_bourque1024.jpg' /> | ||
</div> | ||
) | ||
``` | ||
### Loading the image 300px prior to scroll | ||
```jsx | ||
const MyComponent = () => ( | ||
<div> | ||
<LazyLoad height={762} offset={300}> | ||
<img src='http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg' /> | ||
</LazyLoad> | ||
<div className="filler" /> | ||
<LazyLoad height={480} offsetHorizontal={50}> | ||
<img src='http://apod.nasa.gov/apod/image/1502/MarsPlume_jaeschke_480.gif' /> | ||
</div> | ||
) | ||
``` | ||
### Loading image only when 95% of it is in the viewport. **note** a width must be specified. | ||
```jsx | ||
const MyComponent = () => ( | ||
<div> | ||
<LazyLoad height={762} width={400} threshold={0.95}> | ||
<img src='http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg' /> | ||
</LazyLoad> | ||
<div className="filler" /> | ||
<LazyLoad | ||
height={720} | ||
onContentVisible={() => console.log('look ma I have been lazyloaded!')} | ||
> | ||
<img src='http://apod.nasa.gov/apod/image/1502/ToadSky_Lane_1080_annotated.jpg' /> | ||
</div> | ||
) | ||
``` | ||
### Performing a side effect once your image is loaded | ||
```jsx | ||
const MyComponent = () => ( | ||
<div> | ||
<LazyLoad height={762} width={400} threshold={0.95} onContentVisible={() => {console.log('loaded!')}}> | ||
<img src='http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg' /> | ||
</LazyLoad> | ||
<div className="filler" /> | ||
</div> | ||
); | ||
) | ||
``` | ||
## Props | ||
@@ -59,46 +89,9 @@ | ||
Aliases: `threshold` | ||
The `offset` option allows you to specify how far below, above, to the left, and to the right of the viewport you want to _begin_ displaying your content. If you specify `0`, your content will be displayed as soon as it is visible in the viewport, if you want to load _1000px_ below or above the viewport, use `1000`. | ||
#### offsetVertical | ||
Type: `Number|String` Default: `offset`'s value | ||
#### threshold | ||
Type: `Number` Default: `0` | ||
The `offsetVertical` option allows you to specify how far above and below the viewport you want to _begin_ displaying your content. | ||
This `threshold` option allows you to specify how much of the element must be shown on the screen prior to loading. This requires a _width_ and _height_ to be set on the `<LazyLoad>` component in order for the browser to calcualte the viewable area. | ||
#### offsetHorizontal | ||
Type: `Number|String` Default: `offset`'s value | ||
The `offsetHorizontal` option allows you to specify how far to the left and right of the viewport you want to _begin_ displaying your contet. | ||
#### offsetTop | ||
Type: `Number|String` Default: `offsetVertical`'s value | ||
The `offsetTop` option allows you to specify how far above the viewport you want to _begin_ displaying your content. | ||
#### offsetBottom | ||
Type: `Number|String` Default: `offsetVertical`'s value | ||
The `offsetBottom` option allows you to specify how far below the viewport you want to _begin_ displaying your content. | ||
#### offsetLeft | ||
Type: `Number|String` Default: `offsetVertical`'s value | ||
The `offsetLeft` option allows you to specify how far to left of the viewport you want to _begin_ displaying your content. | ||
#### offsetRight | ||
Type: `Number|String` Default: `offsetVertical`'s value | ||
The `offsetRight` option allows you to specify how far to the right of the viewport you want to _begin_ displaying your content. | ||
#### throttle | ||
Type: `Number|String` Default: `250` | ||
The throttle is managed by an internal function that prevents performance issues from continuous firing of `scroll` events. Using a throttle will set a small timeout when the user scrolls and will keep throttling until the user stops. The default is `250` milliseconds. | ||
#### debounce | ||
Type: `Boolean` Default: `true` | ||
By default the throttling function is actually a [debounce](https://lodash.com/docs#debounce) function so that the checking function is only triggered after a user stops scrolling. To use traditional throttling where it will only check the loadable content every `throttle` milliseconds, set `debounce` to `false`. | ||
#### height | ||
@@ -118,1 +111,18 @@ Type: `String|Number` | ||
A callback function to execute when the content appears on the screen. | ||
## Building LazyLoad | ||
``` | ||
npm run build | ||
``` | ||
## Running examples | ||
``` | ||
cd examples/basic | ||
npm run dev | ||
``` | ||
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
15
126
0
1
Yes
13378
7
153
+ Added@vitejs/plugin-react@^2.0.1
+ Addedtypescript@^4.7.4
+ Addedvite@^3.0.9
+ Addedvite-plugin-dts@^1.4.1
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/compat-data@7.26.2(transitive)
+ Added@babel/core@7.26.0(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-annotate-as-pure@7.25.9(transitive)
+ Added@babel/helper-compilation-targets@7.25.9(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-module-transforms@7.26.0(transitive)
+ Added@babel/helper-plugin-utils@7.25.9(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/helper-validator-option@7.25.9(transitive)
+ Added@babel/helpers@7.26.0(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/plugin-syntax-jsx@7.25.9(transitive)
+ Added@babel/plugin-transform-react-jsx@7.25.9(transitive)
+ Added@babel/plugin-transform-react-jsx-development@7.25.9(transitive)
+ Added@babel/plugin-transform-react-jsx-self@7.25.9(transitive)
+ Added@babel/plugin-transform-react-jsx-source@7.25.9(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@esbuild/android-arm@0.15.18(transitive)
+ Added@esbuild/linux-loong64@0.15.18(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@microsoft/api-extractor@7.47.11(transitive)
+ Added@microsoft/api-extractor-model@7.29.8(transitive)
+ Added@microsoft/tsdoc@0.15.0(transitive)
+ Added@microsoft/tsdoc-config@0.17.0(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@rollup/pluginutils@5.1.3(transitive)
+ Added@rushstack/node-core-library@3.66.15.9.0(transitive)
+ Added@rushstack/rig-package@0.5.3(transitive)
+ Added@rushstack/terminal@0.14.2(transitive)
+ Added@rushstack/ts-command-line@4.23.0(transitive)
+ Added@ts-morph/common@0.18.1(transitive)
+ Added@types/argparse@1.0.38(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@vitejs/plugin-react@2.2.0(transitive)
+ Addedajv@8.12.08.13.0(transitive)
+ Addedajv-draft-04@1.0.0(transitive)
+ Addedajv-formats@3.0.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.112.0.1(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbrowserslist@4.24.2(transitive)
+ Addedcaniuse-lite@1.0.30001680(transitive)
+ Addedcode-block-writer@11.0.3(transitive)
+ Addedcolors@1.2.5(transitive)
+ Addedcommander@10.0.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedelectron-to-chromium@1.5.62(transitive)
+ Addedesbuild@0.15.18(transitive)
+ Addedesbuild-android-64@0.15.18(transitive)
+ Addedesbuild-android-arm64@0.15.18(transitive)
+ Addedesbuild-darwin-64@0.15.18(transitive)
+ Addedesbuild-darwin-arm64@0.15.18(transitive)
+ Addedesbuild-freebsd-64@0.15.18(transitive)
+ Addedesbuild-freebsd-arm64@0.15.18(transitive)
+ Addedesbuild-linux-32@0.15.18(transitive)
+ Addedesbuild-linux-64@0.15.18(transitive)
+ Addedesbuild-linux-arm@0.15.18(transitive)
+ Addedesbuild-linux-arm64@0.15.18(transitive)
+ Addedesbuild-linux-mips64le@0.15.18(transitive)
+ Addedesbuild-linux-ppc64le@0.15.18(transitive)
+ Addedesbuild-linux-riscv64@0.15.18(transitive)
+ Addedesbuild-linux-s390x@0.15.18(transitive)
+ Addedesbuild-netbsd-64@0.15.18(transitive)
+ Addedesbuild-openbsd-64@0.15.18(transitive)
+ Addedesbuild-sunos-64@0.15.18(transitive)
+ Addedesbuild-windows-32@0.15.18(transitive)
+ Addedesbuild-windows-64@0.15.18(transitive)
+ Addedesbuild-windows-arm64@0.15.18(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfs-extra@10.1.07.0.1(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedimport-lazy@4.0.0(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedjju@1.4.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedjsonfile@4.0.06.1.0(transitive)
+ Addedkolorist@1.8.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.get@4.4.2(transitive)
+ Addedlodash.isequal@4.5.0(transitive)
+ Addedlru-cache@5.1.16.0.0(transitive)
+ Addedmagic-string@0.26.7(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedminimatch@3.0.85.1.6(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedms@2.1.3(transitive)
+ Addednanoid@3.3.7(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpath-browserify@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpicomatch@2.3.14.0.2(transitive)
+ Addedpostcss@8.4.49(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreact@18.3.1(transitive)
+ Addedreact-dom@18.3.1(transitive)
+ Addedreact-refresh@0.14.2(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrollup@2.79.2(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedscheduler@0.23.2(transitive)
+ Addedsemver@6.3.17.5.4(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedsourcemap-codec@1.4.8(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstring-argv@0.3.2(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@8.1.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedts-morph@17.0.1(transitive)
+ Addedtypescript@4.9.55.4.2(transitive)
+ Addeduniversalify@0.1.22.0.1(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedvalidator@13.12.0(transitive)
+ Addedvite@3.2.11(transitive)
+ Addedvite-plugin-dts@1.7.3(transitive)
+ Addedyallist@3.1.14.0.0(transitive)
+ Addedz-schema@5.0.6(transitive)
- Removedeventlistener@0.0.1
- Removedlodash.debounce@^4.0.0
- Removedlodash.throttle@^4.0.0
- Removedprop-types@^15.5.8
- Removedeventlistener@0.0.1(transitive)
- Removedlodash.debounce@4.0.8(transitive)
- Removedlodash.throttle@4.1.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact@17.0.2(transitive)
- Removedreact-dom@17.0.2(transitive)
- Removedreact-is@16.13.1(transitive)
- Removedscheduler@0.20.2(transitive)