122
rated 0 times
[
125]
[
3]
/ answers: 1 / hits: 6018
/ 3 Years ago, sun, may 23, 2021, 12:00:00
Here is my useEffect
with a simple clean-up function () => { inbox?.destroy(); }
, but it raises a warning when I let the clean-up function there. Why is that, isn't the clean-up function a legit syntax? How to fix it (of course without removing the clean-up function)?
useEffect(() => {
const { currentUser } = initialState!;
let inbox: Talk.Inbox;
if (!currentUser || !talkjsContainerRef.current) return;
Talk.ready.then(async () => {
const me = employeeToUser(currentUser);
window.talkSession = new Talk.Session({ appId, me });
if (id === undefined) {
// me without other => most recent message first
inbox = window.talkSession.createInbox();
} else {
// me with an other => select other
const other = employeeToUser(await readEmployee(Number(id)));
const conversation = window.talkSession.getOrCreateConversation(Talk.oneOnOneId(me, other));
conversation.setParticipant(me);
conversation.setParticipant(other);
inbox = window.talkSession.createInbox({ selected: conversation });
}
inbox.mount(talkjsContainerRef.current);
});
return () => {
inbox?.destroy();
};
}, [id, initialState]);
More From » reactjs