我收到錯誤,我確定這是由于打字稿引起的。這是我試圖開始作業的一個例子。我用js server匯入了幾個筆記。錯誤是 NoteCard.tsx 檔案中 {note} 下的一條紅線。有人可以幫助我了解如何使用這些屬性。
這是我的 notecard.tsx
export default function NoteCard({ note }) { return <div>{note.title}</div>;}
這是我的notes.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>
);
}
uj5u.com熱心網友回復:
嘗試在 NoteCard 功能中添加 props 介面
interface NoteCardProps {
note: {
title: string
}
}
export default function NoteCard({ note }: NoteCardProps) { return <div>{note.title}</div>;}
uj5u.com熱心網友回復:
該隱含的措辭是不是一個巧合。您可以簡單地鍵入該函式,并為其指定顯式型別。
export default function NoteCard({ note }: { note: any }) { return <div>{note.title}</div>;}
這應該修復警告。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/403741.html
標籤:
