以下代码是要附加多个事件侦听器还是 React Native / expo-linking 一次只允许附加一个事件侦听器?
import * as Linking from 'expo-linking'
import { useIsFocused } from '@react-navigation/native'
const MyComponent = () => {
const isFocused = useIsFocused()
useEffect(() => {
fetchData()
Linking.addEventListener('url', _handleEvent)
}, [isFocused])
const fetchData = () => {
// ...
}
const _handleEvent = () => {
// ...
}
return (
<View><View>
)
}
有没有办法检查事件监听器是否已经存在,所以我可以做类似的事情:
useEffect(() => {
fetchData()
if(!eventListenerExists){
Linking.addEventListener('url', _handleEvent)
}
}, [isFocused])
噜噜哒
白板的微信
皈依舞
相关分类