简体   繁体   English

React 在使用 map function 渲染对象数组时抛出错误

[英]React throws error while using map function to render array of objects

my react application throws error when i am using map function.当我使用 map function 时,我的反应应用程序抛出错误。 The similar code seems to be working fine when i use it in sandbox.当我在沙箱中使用类似的代码时,它似乎工作正常。
Error: ENOSPC: System limit for number of file watchers reached, watch So, After creating react project, the error is gone.错误: ENOSPC: System limit for number of file watchers reached, watch所以,创建反应项目后,错误消失了。 but, when i use map function, it doesn't show anything.但是,当我使用 map function 时,它什么也没显示。 localhost:3000 is blank. localhost:3000 为空白。 but, when i comment out createEmojiCard function and use the same code inside app function.但是,当我注释掉createEmojiCard function 并在应用程序 function 中使用相同的代码时。 it works fine.它工作正常。

sample code:示例代码:

import emojis from "../emojipedia";

function createEmojiCard(emoji){
  return(  <dl className="dictionary">
          <div className="term">
          <dt>
            <span className="emoji" role="img" aria-label="Tense Biceps">
              💪
            </span>
            <span>Tense Biceps</span>
          </dt>
        </div>
  </dl>
  );
}
function App() {
  return (
    <div>
      <h1>
        <span>emojipedia</span>
      </h1>
      {emojis.map(createEmojiCard)}

you can do a dependency update npm/yarn install , if it doesn't work maybe many different projects you open in VS Code, close another project and reload your VS Code你可以做一个依赖更新npm/yarn install ,如果它不起作用,可能你在 VS Code 中打开了许多不同的项目,关闭另一个项目并重新加载你的 VS Code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM