啊黑啊 2022-07-13 15:31 采纳率: 0%
浏览 57

react next antd引入自定义svg图片

 react next antd引入自定义svg图片

这样不显示图标,代码里面也不显示,
报错 Warning: [@ant-design/icons] Should have component prop or children.

import { ReactComponent as centerSvg } from "./icon-infor-centre-28-px.svg";

这里去掉ReactComponent as 不显示图标,代码里面同样不显示,
报错 Warning: [@ant-design/icons] Should have component prop or children.

import { centerSvg } from "./icon-infor-centre-28-px.svg";

这样子写又报错Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of AntdIcon.
但是可以显示的,

import centerSvg from "./icon-infor-centre-28-px.svg";

咋办,不显示到底哪里有问题


import React from "react";
import Icon from "@ant-design/icons";

import { ReactComponent as centerSvg } from "./icon-infor-centre-28-px.svg";
import { ReactComponent as homeSvg } from "./icons.svg";
import { ReactComponent as buySvg } from "./icons-3.svg";
import { ReactComponent as referralSvg } from "./icons-4.svg";
import { ReactComponent as setSvg } from "./icons-5.svg";
import { ReactComponent as aboutSvg } from "./icons-2.svg";
import { ReactComponent as NextArrowSvg } from "./icons-next-36-px-2.svg";
import { ReactComponent as PrevArrowSvg } from "./icons-previous-36-px.svg";

const CenterIcon = props => <Icon component={centerSvg} {...props} />;
const HomeIcon = props => <Icon component={homeSvg} {...props} />;
const BuyIcon = props => <Icon component={buySvg} {...props} />;
const ReferralIcon = props => <Icon component={referralSvg} {...props} />;
const SetIcon = props => <Icon component={setSvg} {...props} />;
const AboutIcon = props => <Icon component={aboutSvg} {...props} />;
const NextArrowIcon = props => <Icon component={NextArrowSvg} {...props} />;
const PrevArrowIcon = props => <Icon component={PrevArrowSvg} {...props} />;

export {
  CenterIcon,
  HomeIcon,
  BuyIcon,
  ReferralIcon,
  SetIcon,
  AboutIcon,
  NextArrowIcon,
  PrevArrowIcon
};

  • 写回答

2条回答 默认 最新

  • 崽崽的谷雨 2022-07-13 18:15
    关注

    [@ant-design/icons]应具有组件道具或子级。

    元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:object。

    检查AntdIcon的render方法。

    评论

报告相同问题?

问题事件

  • 修改了问题 7月13日
  • 创建了问题 7月13日

悬赏问题

  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程