Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript &引用;箭头函数应无返回值“;具有有效的清理功能_Javascript_Reactjs_Eslint_Use Effect - Fatal编程技术网

Javascript &引用;箭头函数应无返回值“;具有有效的清理功能

Javascript &引用;箭头函数应无返回值“;具有有效的清理功能,javascript,reactjs,eslint,use-effect,Javascript,Reactjs,Eslint,Use Effect,这是我的useffect,它有一个简单的清理函数()=>{inbox?.destroy();},但是当我让清理函数在那里时,它会发出警告。为什么,清理函数不是合法的语法吗?如何修复它(当然不需要删除清理功能) 可能的修复方法:转向返回到返回未定义 说明: 我违反了法律 此规则要求return语句始终或从不指定值 在第4行,if(!currentUser | |!talkjsContainerRef.current)返回,我的return语句没有指定值,这与我的“清理功能”相矛盾@t.J.Cr

这是我的
useffect
,它有一个简单的清理函数
()=>{inbox?.destroy();}
,但是当我让清理函数在那里时,它会发出警告。为什么,清理函数不是合法的语法吗?如何修复它(当然不需要删除清理功能)


可能的修复方法:转向
返回
返回未定义

说明: 我违反了法律

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


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

@t.J.Crowder我在屏幕截图上捕获了错误消息,它来自VSCode,我没有写出来。我以为你添加了它(就像它周围的框一样)。哇,埃斯林特的措辞很糟糕。
  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]);