An open API service indexing awesome lists of open source software.

https://github.com/trendyol/lazy-component-loader


https://github.com/trendyol/lazy-component-loader

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

# Lazy Load Components Package

This package helps you load components with IntersectionObserver.

| Statements | Branches | Functions | Lines |
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| ![Statements](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) | ![Branches](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) | ![Functions](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) | ![Lines](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) |

## Installation

```
yarn add component-lazy-loader
```

## Usage

Example:

```js
import React from "react";
import LazyComponent from "component-lazy-loader";

function App() {
let length = 100,
i = 0,
arr = Array(length);

while (i < length) arr[i++] = i;
return (


{arr.map((element, index) => {
return (

Placeholder

}
ratio={0.1}
>

Test Component


);
})}

);
}
```

## Options

```ts
export interface LazyLoadComponentsProps {
placeholder: React.Component;
children: React.Component;
force?: boolean; // default false
ratio?: number; // default 0.1
onVisible?: Function;
}
```