簡體   English   中英

如何自動更新我的頁面以添加輸入的內容? 我收到 TypeError

[英]How do I automatically update my page to add what is inputted? I am receiving TypeError

我正在向包含所有食譜的頁面添加食譜。 當我在表單中添加配方時,狀態會正確更新。 但是,我必須刷新所有食譜頁面才能顯示新添加的食譜。 它一直說我的 id 屬性未定義。我將如何修復它以便它會自動更新?

render() { const { recipes } = this.props;

return (
  <div>
    {
      recipes.map(recipe => {
        return (
          <div key={recipe.id}>
            <Link to={`/recipes/${recipe.id}`} key={recipe.id}>
              <h2>{recipe.name}</h2>
            </Link>
            <div>{recipe.cuisine}</div>
            <img src={recipe.imageUrl} />

類型錯誤:無法讀取未定義的屬性“id”

您沒有添加定義的配方對象。 Console.log你的props.recipes ,你會看到,新添加的一個是undefinednull 檢查更新食譜列表的功能,並確保將有效的食譜添加到您的列表中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM