I have 2 rooms {roomId: room1, roomId: room2}
and I want to save Object for each rooms on localStorage.
The object looks like
let notifiedRoom = {
roomId: roomId,
dismissed: true
};
The notifiedRoom Object is saved on localStorage when the user closes notification for respective room.
import React from 'react';
import { toast } from 'react-toastify';
const RoomNotification = (props) => {
const { roomId, message } = props;
const setLocalStorage = (roomId) => {
let notifiedRoom = {
roomId: roomId,
dismissed: true
};
localStorage.setItem('notifiedRoom', JSON.stringify(notifiedRoom));
};
const notify = () => {
toast(<div><p>{roomId}</p><p>{message}</p></div>,
{
toastId: roomId,
position: "top-center",
draggable: true,
onClose:() => setLocalStorage(roomId)
});
};
}
the problem I have is this will only save a object for a room at a time. So if you close room1 Notification then on localStorage
there is roomId: room01, dismissed: true
, if I close room2 Notification then the previous localStorage object for room1 is overwritten by room2.
I only need it to overwrite if the roomId matches. Else just create new object for every different roomId on locatStorage.
Many thanks