useSubscription closure not updated
Draeken opened this issue · 3 comments
Hello!
I have a similar use of useSubscription which access closure (a prop).
const [debug, setDebug] = useState(false)
const subscription = useSubscription(events$, null, error => {
if (debug) {
console.log(error)
}
})
But when the prop is updated, and useSubscription's event handler is fired, it's always the old prop's value. I could add the prop in the observable used by useSubscription but it's cumbersome. Is there another way?
Hi! Are you using the latest version?
It should work on v2. You can see the test here:
observable-hooks/test/use-subscription.spec.ts
Lines 120 to 123 in f8022b5
If you are using v1 you have to create an extra Observable to track values and also useObservableCallback
to track the latest callback. In v2 I've simplify the API with just useSubscription
and also with a performance boost.
I was using v1 😮
It's much simpler now, thanks!