0

I am trying to convert an image component wrapper of Next.js but I am having an error below

Type '{ placeholder: "blur"; blurDataURL: string; onLoadingComplete: () => void; className: string; key?: React.Key | null | undefined; crossOrigin?: "" | "anonymous" | "use-credentials" | undefined; ... 269 more ...; alt: string | undefined; }' is not assignable to type '{ key?: React.Key | null | undefined; crossOrigin?: "" | "anonymous" | "use-credentials" | undefined; decoding?: "async" | "auto" | "sync" | undefined; referrerPolicy?: React.HTMLAttributeReferrerPolicy | undefined; ... 270 more ...; alt: string | undefined; }'.
  Object literal may only specify known properties, and 'className' does not exist in type '{ key?: Key | null | undefined; crossOrigin?: "" | "anonymous" | "use-credentials" | undefined; decoding?: "async" | "auto" | "sync" | undefined; referrerPolicy?: HTMLAttributeReferrerPolicy | undefined; ... 270 more ...; alt: string | undefined; }'.

Image.tsx

import Img from 'next/future/image';

import { GbImagePlaceholder } from '../icons';
import isEmpty from 'lodash/isEmpty';
import imageDataBlurUrl from '../../utils/image';
import cx from 'classnames';
import { useState } from 'react';
import React from 'react';
import { ImageProps } from 'next/image';

export interface FutureImageProps extends ImageProps {
    showDefault?: Boolean;
    blur?: Boolean;
    className: string;
}

const FutureImage = (props: FutureImageProps) => {
    const {
        width,
        height,
        src,
        showDefault = true,
        blur = true,
        className,
        alt,
        ...rest
    } = props;
    const [isLoading, setLoading] = useState(true);

    if (isEmpty(src) && showDefault) {
        return <GbImagePlaceholder width="100%" height="100%" />;
    }

    let attributes = {
        src: src,
        width: width,
        height: height,
        alt,
        ...rest,
    };

    if (blur) {
        attributes = {
            ...attributes,
            placeholder: 'blur',
            blurDataURL: imageDataBlurUrl(10, 10),
            onLoadingComplete: () => setLoading(false),
            className: cx(
                className,
                'duration-700 ease-in-out',
                isLoading
                    ? 'grayscale blur-3xl scale-110'
                    : 'grayscale-0 blur-0 scale-100'
            ),
        };
    }
    return <Img {...attributes} />;
};

export default FutureImage;

To be honest, I don't know how to fix the error with classname and Img error and I need help to fix the error. Please see image below enter image description here

Nick Vu
  • 14,512
  • 4
  • 21
  • 31
jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65
  • Check if this is related to your issue. https://stackoverflow.com/questions/69576762/property-classname-does-not-exist-on-type-props-reactnode – Gaurav Chauhan Oct 04 '22 at 07:08
  • I tried adding a definition for classname but did not work – jameshwart lopez Oct 04 '22 at 07:12
  • For Img component is it properly exported? – Gaurav Chauhan Oct 04 '22 at 07:24
  • Please consider providing a [mre] suitable for demonstrated your issue when pasted, as-is, into a standalone IDE. Right now there are a lot of external dependencies that make it impossible for anyone but you to test. If you do decide to [edit] to a self-contained version and want me to take another look, please comment and mention @jcalz to notify me. Good luck! – jcalz Oct 04 '22 at 16:39

0 Answers0