0

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;
}
Ada
  • 559
  • 1
  • 3
  • 19

1 Answers1

0

Any particular reason you can't do it the same way you do it with type using the [] syntax?

.users[userId] = true

ApplePearPerson
  • 4,209
  • 4
  • 21
  • 36