修正:我在全球范围内卸载了VScode,打字稿和eslint。一旦我重新安装了VScode,一切都会恢复正常。
更新:安装@ types / react库后,我仍然仅对RecipeList.js和Recipe.js都得到类似的错误,如属性“ props”中提到的在 类型“ Home”上不存在或TypeScript属性“ props”不存在:
属性'recipes'在类型'Readonly <{children?:ReactNode;上不存在。}>和只读<{}>'。
原文:所以我是React的新手,由于某种原因,在VSCode上,尝试访问RecipeList.js和Recipe.js的.props时遇到语法错误。
这是Recipe.js的代码示例:
import React, {Component} from 'react';
import "./Recipe.css";
class Recipe extends Component {
// props: any; uncommenting this will fix the bug
render() {
// don't have to use return and parentheses for arrow with JSX
const ingredients = this.props.ingredients.map((ing, ind) => (
<li key={ind}>{ing}</li>
));
const {title, img, instructions} = this.props
return (
<div className="recipe-card">
<div className="recipe-card-img">
<img src={img} alt={title}/> …Run Code Online (Sandbox Code Playgroud)