Created
November 6, 2020 17:30
-
-
Save BasixKOR/d1c9e41fd5888cd1bcaba86d45e09a7b to your computer and use it in GitHub Desktop.
Trying to mix Img and next/image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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