For some time I've seen that it's important to bring direct replies to our chat messages into our rooms and so I've tried to find a solution for this. Without further ado, I'll describe part of how it happened 1. I've added an extra field to the message table, which will store the key for each message replied to. 2. Next, I created a function in BACKEND that would check if each new message sent by a user had that field other than NULL, if it met this condition then a new div with the message to be replied to is added to that message. But how would I send that new field value to the backend? Ooh! that was my big problem. Since I'm using XMLHttpRequest in javascript, this could cause some communication problems, and indeed it did. So to solve part of this problem I created the handleLinkClick() function in javascript to pass me this value directly from the link in the message to be replied to (I hope you understood me kkkk). And this value is passed to another function getRq() which is responsible for sending it to the backend and then saving it in the database. Shit, but there's a problem! This value is sent to the backend over and over again every time the user replies to a message. How can I solve this🤷♀️🤷♀️? Help me
After analyzing the code for some time, I managed to solve the problem. What was causing the repetition? > The problem was in the storage of the parameter value, which was not destroyed as soon as the first response was sent. Solution: > Within the function that takes the same parameter, we had to add another function to destroy that value as soon as the first message/reply was sent, thus avoiding the repetition of the reply in the same message. The code ```js if (mValue) { mValueInput.value = mValue; // Stores the value console.log('mValue updated to:', mValue); // Sets up the delayed cleanup actions const clearMValue = () => { setTimeout(() => { mValueInput.value = ''; // Clears the value console.log('mValue cleared after delay.'); }, 2000); // 2-second delay }; } ```