繁体   English   中英

“箭头 function 预期没有返回值”在 useEffect 中清理 function

[英]"arrow function expected no return value" with clean-up function in useEffect

这是我的useEffect与简单的清理 function () => { inbox?.destroy(); } () => { inbox?.destroy(); } ,但是当我在那里清理 function 时会发出警告。 为什么,清理 function 不是合法的语法? 如何修复它(当然不删除清理 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]);

一个可能的解决方法:转弯return; return undefined;

在此处输入图像描述

解释:

我违反了consistent-return规则

此规则要求return语句始终或从不指定值

在第 4 行, if (.currentUser ||;talkjsContainerRef.current) return; ,我的return语句没有指定值,这与我的“清理功能”相矛盾

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM