React Props 缺少验证

问题描述 投票:0回答:1

在使用 React 的 props 时,我的代码中有以下“警告”。一切似乎都工作正常,但是,我的道具上有红色下划线,当我将它们悬停时,我看到:道具验证/道具类型中缺少这个。任何人都可以帮助我,我将不胜感激?

export function Order(props) {
  const { id, img, title, description, price } = props;
  return (
    <>
      <div id={`product-id-${id}`}>
        <img
          id={`product-image-${id}`}
          className="product-image"
          src={img}
          alt="This is a product image"
        />
        <h3 className="order-title">${title}</h3>
        <p>${description}</p>
        <p className="price">$ ${price}</p>

        <div>
          <button id={id} className="order-btn">
            Add to Cart
          </button>
        </div>
      </div>
    </>
  );
}

一切正常,但我假设我的代码有问题

javascript reactjs frontend react-props
1个回答
0
投票

错误/警告似乎来自 ESLint(警告标题表明了这一点)。

您可以通过将以下内容添加到您的

.eslintrc.json
.eslintrc.js
文件中来告诉 ESLint 忽略 prop-type linting(如果该文件尚不存在,则在项目根目录中创建该文件):

  "overrides": [
    {
      "rules": {
        "react/prop-types": "off"
      }
    }]
© www.soinside.com 2019 - 2024. All rights reserved.