React.createElement: type is invalid expected a string (for built-in components) but got: undefined

报错代码:

import { ReactComponent as Back } from '@/assets/back.svg';

<div className={styles['title-back']} onClick={close} style={{color}}>

   <Back></Back>

</div>

报错内容:

希望类型是string或者是组件,但是实际上是undefined。

报错原因:

不同版本的react引入svg的方式不同,旧版本支持以上方式引入svg,新版本引入方式:

import React from 'react';
export default function () {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14">
      <polyline fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" points="19.5 17.5 14.5 22 14.5 22 19.5 26.5" transform="translate(-11 -15)"/>
    </svg>
  );
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值