I am mocking a userId which should be saved inside the users
object of the reactions
object when a certain icon is clicked inside my react component.
Below is a function updateUploadReaction
that is supposed to do that for me. So, when the icon is clicked and a particular userId does not exist, it sets it inside the user
object and adds 1, on clicking again it sets it to false and subtracts 1. So far, this is what I have, I need a guide on exactly how to do that.
reaction object
{
reactions: {
dislike: {
count: 0,
users: {},
},
like: {
count: 0,
users: {},
},
maybe: {
count: 0,
users: {},
},
},
}
function
function updateUploadReaction(id, type, uploads) {
const updatedUploads = new Map([...uploads.entries()]);
const upload = updatedUploads.get(id);
const userId = uuid();
uploads.forEach(() => {
if (//check if userId exists) {
upload.reactions[type].count += 1;
upload.reactions[type].users.(// user Id value) = true;
} else {
upload.reactions[type].count -= 1;
upload.reactions[type].users.(// user Id value) = false;
}
});
updatedUploads.set(id, upload);
return updatedUploads;
}