类型'{src:String; }'不能分配给'SVGProps <SVGImageElement>

时间:2019-12-23 12:33:37

标签: reactjs typescript

当我做这样的事情时,我得到以下错误

import React from 'react'
import "./../../styles/container.scss"
import './../../styles/common.scss'

interface containerProps {
  icon: String,
  heading: String,
  para: String, 
}


export const IconRowContainer = ({heading, para, icon}: containerProps) => {
  return (
    <div className="icon-row-container-main-div">
      <image src={icon} />
      <div>
        <h2 className="secondary-heading icon-row-container-heading"> {heading} </h2>
        <p className="para icon-row-container-para"> {para}</p>
      </div>
    </div>
  )
}

错误

  

类型'{src:字符串; }'无法分配给type   'SVGProps'。类型不存在属性“ src”   SVGProps

您知道我在这里可能做错了什么吗?

2 个答案:

答案 0 :(得分:2)

使用<img src={icon} />代替<image src={icon} />

答案 1 :(得分:0)

所有基本类型都应小写,并且本地HTML标签列表中没有图像标签,您必须使用 img 。< / p>

import React from 'react'
import "./../../styles/container.scss"
import './../../styles/common.scss'

interface containerProps {
  icon: string,
  heading: string,
  para: string, 
}


export const IconRowContainer: React.FC<containerProps> = ({heading, para, icon}) => {
  return (
    <div className="icon-row-container-main-div">
      <img src={icon} />
      <div>
        <h2 className="secondary-heading icon-row-container-heading"> {heading} </h2>
        <p className="para icon-row-container-para"> {para}</p>
      </div>
    </div>
  )
}