报错代码:
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>
);
}