简体   繁体   English

使用 useEffect 和取消订阅时,它会在 function 警告中给出 Missing return type

[英]While using useEffect and unsubscribe, it gives Missing return type on function warning

I'm using the following useEffect hook and in the hook, I'm setting a listener and unsubscribing to this listener inside a return.我正在使用以下 useEffect 挂钩,在挂钩中,我正在设置一个监听器并在返回中取消订阅该监听器。

useEffect(() => {
        const listener = firebase.auth.onAuthStateChanged(authUser => {        
        })
        return () => listener()
      }, [])

But it's giving the following warning Missing return type on function warning on this line: return () => listener()但它给出了以下警告 Missing return type on function warning on this line: return () => listener()

What is the correct way of typing it without disabled something in eslint?在 eslint 中不禁用某些东西的情况下输入它的正确方法是什么?

Any help is very welcome!非常欢迎任何帮助!

This should work:这应该工作:

Add void in your arrow function declaration after return返回后在箭头 function 声明中添加void

useEffect(() => {
    const listener = firebase.auth.onAuthStateChanged(authUser => {        
    })
    return ():void => listener()
  }, [])

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

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