I am working on one React.js Application where i need to show checkbox checked ,if user is already present in selected users. I am able to implement that logic ,but the problem is , i have to compare user with thousand of other users to check if user is already in selected users,as it makes my application very slow to compare with thousands of users . How can optimize this List rendering,
const isSelectedArea = (user) => {
selectedUsers.forEach((u) => {
if (u.find((a) => a._id === user._id)) {
return true;
}
});
};
<span className={`block border-gray-200 bg-gray-200 ${isSelectedUser(user) ? "check":" "}`}></span>