1.0.5 • Published 3 years ago

component-lazy-loader v1.0.5

Weekly downloads
40
License
ISC
Repository
github
Last release
3 years ago

Lazy Load Components Package

This package helps you load components with IntersectionObserver.

StatementsBranchesFunctionsLines
StatementsBranchesFunctionsLines

Installation

yarn install @trendyol/component-lazy-loader

Usage

Example:

import React from "react";
import LazyComponent from "@trendyol/component-lazy-loader";

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

  while (i < length) arr[i++] = i;
  return (
    <div>
      {arr.map((element, index) => {
        return (
          <LazyComponent
            placeholder={
              <div
                key={index}
                style={{
                  height: 100,
                  backgroundColor: "red",
                  marginBottom: 10,
                }}
              >
                Placeholder
              </div>
            }
            ratio={0.1}
          >
            <div
              key={index}
              style={{
                height: 100,
                backgroundColor: "lightblue",
                marginBottom: 10,
              }}
            >
              Test Component
            </div>
          </LazyComponent>
        );
      })}
    </div>
  );
}

Options

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

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago