{ inbox?.destroy(); } ,但是当我在那里使用清理功能时会发出警告。为什么,清理功能不是合法的语法吗?如何修复它(当然不删除清-6ren">
gpt4 book ai didi

javascript - "arrow function expected no return value"带有清理功能的useEffect

转载 作者:行者123 更新时间:2023-12-04 16:37:34 39 4
gpt4 key购买 nike

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

最佳答案

一个可能的修复:return;return undefined; enter image description here
解释:
我违反了 consistent-return rule

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


在第 4 行, if (!currentUser || !talkjsContainerRef.current) return; , 我的 return声明 未指定值 ,即 与我的“清理功能”相矛盾 .

关于javascript - "arrow function expected no return value"带有清理功能的useEffect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67658900/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com