gpt4 book ai didi

reactjs - 绑定(bind)元素 'note' 隐式具有 'any' 类型

转载 作者:行者123 更新时间:2023-12-02 16:01:20 25 4
gpt4 key购买 nike

我收到了我确定是 typescript 引起的错误。这是我试图开始工作的一个例子。我使用 js 服务器导入一些注释。错误是 NoteCard.tsx 文件中 {note} 下的红线。有人可以帮助我了解如何使用这些属性。

这是我的notecard.tsx

export default function NoteCard({ note }) {  return <div>{note.title}</div>;}

这是我的笔记.tsx

export default function Notes() {
const [notes, setNotes] = useState<any[]>([]);

useEffect(() => {
fetch("http://localhost:8000/notes")
.then((res) => res.json())
.then((data) => setNotes(data));
}, []);

return (
<Container>
<Grid container>
{notes.map((note) => (
<Grid item key={note.id} xs={4} md={4} lg={4}>
<NoteCard note={note} />
{/* <Paper>{note.title}</Paper> */}
</Grid>
))}
</Grid>
</Container>
);
}

最佳答案

隐含 的措辞并非巧合。您可以简单地键入该函数,并为其指定一个显式类型。

export default function NoteCard({ note }: { note: any }) {  return <div>{note.title}</div>;}

这应该可以修复警告。

关于reactjs - 绑定(bind)元素 'note' 隐式具有 'any' 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70584947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com