我剛剛寫了一個反應應用程式,現在我很難找出發生了什么。錯誤日志是不夠的。
錯誤:
Uncaught Error: Objects are not valid as a React child (found: object with keys {id, ref}). If you meant to render a collection of children, use an array instead.
我在代碼中找不到將物件作為組件提供的任何地方。
它還給了我一個提示,物件有鍵{id, ref},但問題是我有多個帶有這些鍵的物件,也許鍵的完整串列會有所幫助。
uj5u.com熱心網友回復:
當您嘗試渲染 時會發生這種錯誤Object,就像您嘗試渲染file具有結構的
{
name: string,
size: number
}
你直接將它渲染為
<div>{file}</div>
它會導致你得到的錯誤
Uncaught Error: Objects are not valid as a React child (found: object with keys {id, ref}). If you meant to render a collection of children, use an array instead.
這可以通過這樣做來糾正
<div>{file.name} and {file.size}</div>
uj5u.com熱心網友回復:
有沒有辦法以互動方式除錯反應
是的。首先,從瀏覽器的商店安裝 React Dev Tools。這將使您在除錯方面有很長的路要走。
您還可以使用 Web Storm 之類的工具來除錯 React。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/369621.html
標籤:反应
