Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/farbenmeer/next-image-autosize

A wrapper around next/image that does not require width and height to be specified.
https://github.com/farbenmeer/next-image-autosize

nextjs storybook

Last synced: 2 months ago
JSON representation

A wrapper around next/image that does not require width and height to be specified.

Awesome Lists containing this project

README

        

# next-image-autosize
A wrapper around [next/image](https://nextjs.org/docs/api-reference/next/image) that automatically sets `width` and `height`.

This is useful in testing and development-environments where `next-image-loader` is not available (e.G. [storybook](https://storybook.js.org/)).
It will render a next/image without knowing the `width` and `height` beforehand by rendering a plain `` first, then reading out the image dimensions and replacing the `` with next/image.

## Warning
*DO NOT USE THIS IN PRODUCTION*
It will cause layout shift on two subsequent renders.

## Usage

### Storybook
```js
// .storybook/preview.js
import * as NextImage from 'next/image'
import NextImageAutosize from '@farbenmeer/next-image-autosize'

const OriginalNextImage = NextImage.default

Object.defineProperty(NextImage, 'default', {
configurable: true,
value: NextImageAutosize
})
```