mardi 26 octobre 2021

How do i write a conditional for the possibility of an empty array

I have a users list that im mapping over in a little side bar. Theres a possiblity that there can be no users. So I would like the side bar to say none if theres no users. I tried the below method but it seems like its still registering the user, even if its 0. I've tried (user === null) and (user.length < 1) but just cant seem to get it.

{usersList.map((user) => {
  if (!user) {
    return <h5>none</h5>;
  } else {
    return (
      <h5
        key={user}
      >
        <Link
          to={`/user/${user}`}
          style=
        >
          {user}
        </Link>
      </h5>
    );
  }
})}

Aucun commentaire:

Enregistrer un commentaire