Joshios
07/19/2022, 10:13 PMJesuscc9
07/20/2022, 2:49 AMjsx
const [listener, setListener] = useState()
useEffect(() => {
if (typeof metrics === 'undefined') return
if (typeof listener !== 'undefined') return
console.log('added listener')
setListener(
supabase
.from('metrics')
.on('INSERT', (payload) => {
alert('hola')
})
.subscribe((status) => {
console.log({ status }) // Prints "CLOSED" then "SUBSCRIBED" and finally "CLOSED" idk why
})
)
return () => {
supabase.removeSubscription(listener)
console.log('remove listener')
}
}, [metrics])
as you can see is, very simple, I already tried with a non state variable but still not working
BTW, in my realtime schema, in the subscriptions table I DO have the subscriptionTekey
07/20/2022, 3:01 AMJesuscc9
07/20/2022, 3:02 AMTekey
07/20/2022, 3:04 AMJesuscc9
07/20/2022, 3:06 AMTekey
07/20/2022, 3:06 AMTekey
07/20/2022, 3:06 AMJesuscc9
07/20/2022, 3:07 AMTekey
07/20/2022, 3:07 AMTekey
07/20/2022, 3:07 AMTekey
07/20/2022, 3:07 AMJesuscc9
07/20/2022, 3:10 AMTekey
07/20/2022, 3:11 AMTekey
07/20/2022, 3:11 AMJesuscc9
07/20/2022, 3:15 AMjaitaiwan
07/20/2022, 3:24 AMJesuscc9
07/20/2022, 3:47 AMJesuscc9
07/20/2022, 4:09 AMjsx
useEffect(() => {
console.log('added listener')
const previousSubscriptions = supabase.getSubscriptions()
if (previousSubscriptions.length > 0) return // <--- THIS
const listener = supabase
.from('metrics')
.on('INSERT', handleNewInsert)
.subscribe((status) => {
console.log({ status })
})
return () => {
supabase.removeSubscription(listener)
}
}, [])
Jesuscc9
07/20/2022, 4:09 AMowonwo
07/20/2022, 9:05 AMowonwo
07/20/2022, 9:43 AMltanady
07/20/2022, 9:58 AMowonwo
07/20/2022, 10:24 AMJesuscc9
07/20/2022, 2:17 PMJesuscc9
07/20/2022, 2:18 PMlazerrouge
07/20/2022, 3:04 PMgaryaustin
07/20/2022, 3:09 PMfachofacho
07/20/2022, 4:19 PM