Git Product home page Git Product logo

react-preload-images's Introduction

react-preload-images

This package is not stable!

Introduction

React 이미지 캐싱

image

Get Started

아직 npm 배포 X

Type

여기서는 다음과 같은 형식을 사용합니다.

interface IImagePreloader {
  imagePaths?: string[];
  imageUrls?: string[];
  fallback?: React.ReactElement;
  indicator?: React.ReactElement;
}

Usage

import { Outlet } from 'react-router-dom';
import { ImagePreloader } from 'react-preload-images';

import './App.css';

import img7 from './assets/images/react7.svg';
import img6 from './assets/images/react6.svg';
import img5 from './assets/images/react5.svg';
import img4 from './assets/images/react4.svg';
import img3 from './assets/images/react3.svg';
import img2 from './assets/images/react2.svg';
import img1 from './assets/images/react.svg';

const Root = () => {
  const imgs = [img1, img2, img3, img4, img5, img6, img7];
  return (
    <>
      <Outlet />
      <ImagePreloader
        imagePaths={imgs}
        fallback={<span>Loading!!!</span>}
        indicator={<span>Done</span>}
      />
    </>
  );
};

react-preload-images's People

Contributors

leemir avatar

Stargazers

polee avatar Daisy avatar

Watchers

 avatar

react-preload-images's Issues

Docs: README 예시 코드 포맷 수정

예시 코드에서 React => tsx 로 포맷 변경

highlighting 안되는 오류 해결

AS-IS

  import { Outlet } from 'react-router-dom';
  import { ImagePreloader } from 'react-preload-images';
  
  import './App.css';
  
  import img7 from './assets/images/react7.svg';
  import img6 from './assets/images/react6.svg';
  import img5 from './assets/images/react5.svg';
  import img4 from './assets/images/react4.svg';
  import img3 from './assets/images/react3.svg';
  import img2 from './assets/images/react2.svg';
  import img1 from './assets/images/react.svg';
  
  const Root = () => {
    const imgs = [img1, img2, img3, img4, img5, img6, img7];
    return (
      <>
        <Outlet />
        <ImagePreloader
          imagePaths={imgs}
          fallback={<span>Loading!!!</span>}
          indicator={<span>Done</span>}
        />
      </>
    );
  };

TO-BE

  import { Outlet } from 'react-router-dom';
  import { ImagePreloader } from 'react-preload-images';
  
  import './App.css';
  
  import img7 from './assets/images/react7.svg';
  import img6 from './assets/images/react6.svg';
  import img5 from './assets/images/react5.svg';
  import img4 from './assets/images/react4.svg';
  import img3 from './assets/images/react3.svg';
  import img2 from './assets/images/react2.svg';
  import img1 from './assets/images/react.svg';
  
  const Root = () => {
    const imgs = [img1, img2, img3, img4, img5, img6, img7];
    return (
      <>
        <Outlet />
        <ImagePreloader
          imagePaths={imgs}
          fallback={<span>Loading!!!</span>}
          indicator={<span>Done</span>}
        />
      </>
    );
  };

Feature: 특정 directory 내부에 있는 이미지 전체 preload

preload images by directory path

preLoadImageDirectoryPath 를 추가 후 해당 path 내 이미지 전체를 preload 하는 기능

AS-IS

interface IImagePreloader {
  imagePaths?: string[];
  imageUrls?: string[];
  fallback?: React.ReactElement;
  indicator?: React.ReactElement;
}

function App() {
  return (
    <ImagePreloader
      imagePaths={imgs}
      fallback={<span>Loading!!!</span>}
      indicator={<span>Done</span>}
    />
  )
}

TO-BE

interface IImagePreloader {
  imagePaths?: string[];
  imageUrls?: string[];
  imageDirectoryPath?: string;
  fallback?: React.ReactElement;
  indicator?: React.ReactElement;
}

function App() {
  return (
    <ImagePreloader
      imagePaths={imgs}
      imageDirectoryPath={`/public/preload`}
      fallback={<span>Loading!!!</span>}
      indicator={<span>Done</span>}
    />
  )
}

Feature: loading Percent

Loading Percent

타겟 이미지들이 얼마나 loading 이 되어있는지 알 수 있는 지표를 퍼센트로 나타냄

TO-BE

function Component() {
  const { isLoading, loadingPercent } = useCustomHook(options);

  return (
     isLoading ? loadingPercent : indicator
  );
}

Chore: PeerDependency 버전 수정

React, React-DOM peerDependency 버전 수정

현재 사용하는 기능이 ^18.2.0가 아니라, 더 낮은 버전에서도 사용 가능할 것으로 생각 됌

AS-IS

// package.json

"peerDependencies": {
  "react": "^18.2.0",
  "react-dom": "^18.2.0"
}

TO-BE

// package.json

"peerDependencies": {
  "react": "^18.0.0 | ^17.0.0 | ^16.0.0",
  "react-dom":  "^18.0.0 | ^17.0.0 | ^16.0.0"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.