我收到以下错误:
“'Readonly<{}>' 类型不存在属性 'items'。” 和“属性 'value' 在类型 'Readonly<{}>' 上不存在。”
我正在尝试创建“添加评论,您可以在其中投票和投票”。此外,当我刷新页面时,添加的项目不再可用。
以下代码使用带有打字稿的 React:
Abc.tsx:
export default class Abc extends React.Component{
constructor{
}
handleChange(event){
}
addItem(){
})
this.setState({items:itemsCopy, value:''});
}
render(){
return(
<div>
<input value={this.state.value} onChange={this.handleChange.bind(this)} />
<button onClick = {() => this.addItem()}>Submit</button>
<PostList postList = {this.state.items}
updateScore = {this.updateScore.bind(this)}
removeItem = {this.removeItem.bind(this)}/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud) 我是使用 React 的 Typscript 新手,我在 Google 控制台 Inspect 元素上收到此错误消息。我检查了很多帖子,但无法理解这里出了什么问题。有人可以帮助纠正我的代码中的错误吗?
index.js:1 警告:列表中的每个子项都应该有一个唯一的“key”属性。
检查 的渲染方法
PostList。看Run Code Online (Sandbox Code Playgroud)in div (at PostList.tsx:19) in PostList (at pages/index.tsx:25) in div (at pages/index.tsx:21) in IndexPage (at App.tsx:68) in component (created by Context.Consumer) in Route (at App.tsx:65) in div (at App.tsx:64) in div (at App.tsx:85) in Router (created by BrowserRouter) in BrowserRouter (at App.tsx:84) in App (at src/index.tsx:8)
export default class PostList extends React.Component <Props, Post>{
renderPosts(){
const posts=Object.values (this.props.posts);
return posts.map((n)=> <div>
<h2> <Link to= {`/posts/${n._id}`}> …Run Code Online (Sandbox Code Playgroud)