Skip to content

Instantly share code, notes, and snippets.

@BasixKOR
Created November 6, 2020 17:30
Show Gist options
  • Save BasixKOR/d1c9e41fd5888cd1bcaba86d45e09a7b to your computer and use it in GitHub Desktop.
Save BasixKOR/d1c9e41fd5888cd1bcaba86d45e09a7b to your computer and use it in GitHub Desktop.
Trying to mix Img and next/image
import { Img, HTMLChakraProps } from '@chakra-ui/core';
import NextImage from 'next/image';
import { forwardRef, Ref } from 'react';
type NextImageProps = Parameters<typeof NextImage>[0]; // should be replaced with import from next when it exports its type
export type ImageProps = Omit<
HTMLChakraProps<'img'>,
'src' | 'srcSet' | 'ref' | 'width' | 'height' | 'loading' | 'w' | 'h' // TODO let it work with Chakra width/height props
> &
NextImageProps;
function Image(props: ImageProps, ref: Ref<HTMLImageElement>): JSX.Element {
return <Img ref={ref} as={NextImage} prior {...props} />; // kinda upstream: https://github.com/chakra-ui/chakra-ui/issues/2248
}
export default forwardRef(Image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment