简体   繁体   English

JSX 元素类型“x”没有任何构造或调用签名

[英]JSX element type 'x' does not have any construct or call signatures

I have an imported image and I want to use it in a function.我有一个导入的图像,我想在函数中使用它。 the image:图片:

import  Edit  from  'src/assets/setting/advertising/edit.png';

and this is the function:这是功能:

function getOptions(row) {
        return (
            <div>
                <Edit /> //error
                <img src={Edit} /> //error
            </div>
        );
    }

<Edit /> got this error: <Edit />得到这个错误:

JSX element type 'Edit' does not have any construct or call signatures. JSX 元素类型“编辑”没有任何构造或调用签名。

and <img src={Edit} /> got this error:<img src={Edit} />得到这个错误:

Type 'StaticImageData' is not assignable to type 'string'.ts(2322)类型 'StaticImageData' 不可分配给类型 'string'.ts(2322)

what can I do?我能做什么? thank you.谢谢你。

The two issues are inextricably linked, but they have to be solved differently.这两个问题密不可分,但必须以不同的方式解决。

First issue: You are trying to render an imported static file as a HTML element.第一个问题:您正在尝试将导入的静态文件呈现为 HTML 元素。 You can only render React Components or HTML Elements in React, using that syntax.您只能使用该语法在 React 中渲染 React 组件或 HTML 元素。

Example:例子:

function MyCustomElement() {
    return (
        <div>This is custom element<div>
    );
}

export default function Page() {
    return <div>
        <MyCustomElement />
    </div>;
}

Second Issue: You're trying to pass in an imported static file as the src of an image.第二个问题:您试图将导入的静态文件作为图像的src传入。 You would need to pass in a string.您需要传入一个字符串。

Example:例子:

const PATH_TO_IMAGE = 'src/assets/setting/advertising/edit.png';

function getOptions(row) {
    return (
        <div>
            <img src={PATH_TO_IMAGE} />
        </div>
    );
}

Please, note that the value of "src" must be publicly accessible.请注意,“src”的值必须是可公开访问的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 JSX 元素类型“x”没有任何构造或调用签名 - why JSX element type 'x' does not have any construct or call signatures 打字稿类型定义:TS2604:JSX元素类型“某物”没有任何构造或调用签名 - Typescript type definition: TS2604: JSX element type 'something' does not have any construct or call signatures 错误 JSX 元素类型‘Header’没有任何构造或调用签名”是什么意思? - What does the error JSX element type 'Header' does not have any construct or call signatures" mean? TypeScript 反应 - JSX 元素类型“Modal.Header”没有任何构造或调用签名 - TypeScript react - JSX element type 'Modal.Header' does not have any construct or call signatures JSX 元素类型“GoogleMapReact”没有任何构造或调用 signatures.ts(2604) - JSX element type 'GoogleMapReact' does not have any construct or call signatures.ts(2604) TypeScript 3:JSX 元素类型“组件”没有任何构造或调用签名。 [2604] - TypeScript 3: JSX element type 'Component' does not have any construct or call signatures. [2604] JSX 元素类型 'Route' 没有任何构造或调用签名 - 路由问题 - JSX element type 'Route' does not have any construct or call signatures - route problem TS2604:JSX元素类型“没有任何构造或调用签名 - TS2604: JSX elemy type '' does not have any construct or call signatures 尝试迭代嵌套 arrays 的多个级别不断得到“没有任何构造或调用签名” - Trying to iterate over several levels of nested arrays keep getting 'does not have any construct or call signatures' JSX 元素类型 &#39;ReactElement<any> 不是 JSX 元素的构造函数。 类型 &#39;undefined&#39; 不能分配给类型 &#39;Element | 空值&#39; - JSX element type 'ReactElement<any> is not a constructor function for JSX elements. Type 'undefined' is not assignable to type 'Element | null'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM