1.0.0-rc.3 • Published 3 years ago

@gdo-bzh/suspense-image v1.0.0-rc.3

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

version

suspense-image

NPM JavaScript Style Guide

the package contains:

  • useImageResource hook that handles image pre-loading and a basic pre-caching method (no invalidation cache is implemented)
  • SuspenseImage component based on the useImageResource hook

Install

yarn add @gdo-bzh/suspense-image react

Usage

import React from 'react';
import {CircleDots} from '@gdo-bzh/spinner';
import {SuspenseImage} from '@gdo-bzh/suspense-image';

const Example = () => (
  <ErrorBoundary Fallback={ErrorFallback}>
    <Suspense fallback={<CircleDots size="30px" />}>
      <SuspenseImage src='https://s3.amazonaws.com/uifaces/faces/twitter/plbabin/128.jpg' alt="avatar" />
    </Suspense>
  </ErrorBoundary>
)

Types

type UseImageResource = {
  (src: string): [Resource<string>]
}

type SuspenseImage = Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src'> & {src:string};

License

MIT © gdo-bzh