【问题标题】:Menu.jsx:8 Uncaught TypeError: notes.map is not a function. Whats wrong?Menu.jsx:8 Uncaught TypeError: notes.map 不是函数。怎么了?
【发布时间】:2023-02-05 11:22:04
【问题描述】:
import Note from "../components/Note/Note";

/**
 * @param {object[]} notes - user notes array of objects
 */
const Menu = (notes) => {
  return (
    <>
      {notes.map((val) => (
        <Note
          key={Date.now()}
          title={val.title}
          text={val.text}
          date={val.date}
        />
      ))}
    </>
  );
};

export default Menu;

导出默认菜单;

理论上,该组件会显示您的笔记列表。 prop 是一个对象数组

【问题讨论】:

  • notes 不是大批
  • 你的名字用俄语。可以回答你关于 ru.stackoverflow Uncaught TypeError: map is not a function 的问题吗?
  • const Menu = ({ notes }) =&gt; { 从 components props 对象中解构 notes 属性(假设你有类似 &lt;Menu notes={notes} /&gt; 的东西。

标签: javascript reactjs components


【解决方案1】:

每当我们将父母的道具传递给孩子时。它被传为目的.所以,听笔记是一个对象,其中包含您的数组。

你可以检查它控制台日志(注释)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-29
    • 2019-11-06
    • 2017-09-18
    • 2020-06-05
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多