简体   繁体   English

当我尝试使用 svg 图标时反应返回 [object Object]

[英]React return [object Object] when i try use svg icon

I have a component that returns a container template for a svg image, taking a link to it and a className我有一个组件,它返回一个 svg 图像的容器模板,获取它的链接和一个类名

export function Icon(icon, className) {
  return (
    <span
      className={classNames(['navbar-icon', className])}
      dangerouslySetInnerHTML={{ __html: icon }}
    />
  );
}

then I import it into the component I need然后我将它导入到我需要的组件中

import iconHome from './img/icon/home.svg';
import { Icon } from '../Icon';

and when I use the component to pass it a link to the icon I need, I get [object Object]当我使用该组件将它传递给我需要的图标的链接时,我得到 [object Object]

<Icon icon={link.icon} />

how fix that?如何解决?

尝试这个 :

import {ReactComponent as Icon } from '../Icon';

暂无
暂无

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

相关问题 尝试在 React 中渲染 html 标记时,我得到 [Object object] - I get [Object object] when try to render html tag in React 为什么将 SVG 图像导入我的图标 object 时不显示? - Why is my SVG image not displaying when I import it into my Icon object? 当我尝试将它写到控制台时,React function 显示 object 为空 - React function is showing that object is empty when I try to write it out to the console 当我尝试更新创建的 object 时,React-select 填充 null 值选项 - React-select fills an null value option when I try to update a created object 即使我尝试保存,使用 react 输入字段也会显示合成,并且设置值而不是 defaultValue 正在呈现 [Object, object] - Working with react input field says synthetic even when i try and save, and setting value instead of defaultValue is rendering [Object, object] 在对象中键入 svg 元素反应 - typing svg element react in an object 为什么当我尝试在我的功能组件中使用来自道具 object 的匹配参数时它会失败? - Why it fails when I try to use match parameter from props object in my functional component? 为什么我不能在React中返回对象 - Why can't I return an object in React React intl return [object Object] - React intl return [object Object] 当我尝试将反应项目中的 favicon 重命名为“favicon.ico”时,图标更改为反应徽标 - When I try to rename a favicon in a react project to "favicon.ico" the icon changes to react logo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM