“arrow function expected no return value” with clean-up function in useEffect

Asked By: Anonymous

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)?

enter image description here

  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]);

Solution

Answered By: Anonymous

A possible fix: turn return; to return undefined;

enter image description here

Explanation:

I had violated the consistent-return rule

This rule requires return statements to either always or never specify values

At line 4, if (!currentUser || !talkjsContainerRef.current) return;, my return statement didn’t specify a value, which is contradictory to my "clean-up function".

techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno