简体   繁体   English

× TypeError:无法读取未定义的属性“地图”。 发现错误

[英]× TypeError: Cannot read property 'map' of undefined. found error

Can anyone pls help me out with this problem?谁能帮我解决这个问题?

const Users = ({ users, loading }) => {
  if (loading) {
    return <Spinner />
  } else {
    return (
      <div style={userStyle}>
        {users.map((user) => (
          <UserItem key={users.id} user={user} />
        ))}
      </div>
    )
  }
}

use conditional operator && on before map在 map 之前使用条件运算符&&

const Users = ({ users, loading }) => {
  if (loading) {
    return <Spinner />
  } else {
    return (
      <div style={userStyle}>
        {users && users.map((user) => (
          <UserItem key={user.id} user={user} />
        ))}
      </div>
    )
  }
}

Inside the map, you should use user not users so the code will be在 map 内部,您应该使用用户而不是用户,因此代码将是

{ users.map((user) => (
          <UserItem key={user.id} user={user} />
))}

Because, you are passing user as a argument for callback function not users.

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

相关问题 TypeError:无法读取未定义的属性“地图”。 反应 - TypeError: Cannot read property 'map' of undefined. React 类型错误:无法读取未定义的属性“地图”。 反应 js - TypeError: Cannot read property 'map' of undefined. React js 错误类型错误:无法读取未定义的属性“toLowerCase”。 离子 3 - ERROR TypeError: Cannot read property 'toLowerCase' of undefined. Ionic 3 “ typeError:无法读取未定义的属性“用户名”。” - “typeError: Cannot read property 'username' of undefined.” TypeError:无法读取未定义的属性“地图”错误 - TypeError: Cannot read property 'map' of undefined" error TypeError:无法读取未定义的属性“地图”。 找不到解决办法 - TypeError: Cannot read property 'map' of undefined. Can't find a solution TypeError:无法读取未定义的属性“ get”。 是npm的问题吗? - TypeError: Cannot read property 'get' of undefined. Is npm the issue? TypeError:无法读取未定义的属性“ 0”。 React Redux应用 - TypeError: Cannot read property '0' of undefined. React Redux App 未处理的拒绝(TypeError):无法读取未定义的属性“扩展”。 (GraphQL) - Unhandled Rejection (TypeError): Cannot read property 'extensions' of undefined. (GraphQL) TypeError:无法读取未定义的属性&#39;addTopic&#39;。 我是盲人吗? - TypeError: Cannot read property 'addTopic' of undefined. Am I blind?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM