You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
I'm using React and I want to be able to cancel the postscribe load if my component unmounts before the script is loaded. Why? Because React will complain, rightly so, if I try and do things with an unmounted component because in some cases, when the afterAsync callback is called, the component is gone. I need to cancel it from triggering, naturally I'd want to cancel it within my componentWillUnmount hook.
Looking into the documentation, it looks like postscribe(...) returns an object that you can call .cancel() on. So I did that, but the error I get is:
args.stream.abort is not a function
This is referring to the WritableStream class and looking into it, I couldn't see anywhere that an abort() method exists.
Here is how I'm using the code in a React component in componentDidMount I call this:
So I guess my ultimate question is, if abort() doesn't really exist on the WritableStream object, is there any other suggestion on how I can cancel to stop the afterAsync from triggering when the component is unmounted before the postscribe script loads.
The text was updated successfully, but these errors were encountered:
My expectation would also be that even if the postscribe script loads successfully, I should be able to call this.postscribeCancel.cancel() and have no error thrown, it would just be a no-op at that point because there is nothing left to cancel.
I'm using React and I want to be able to cancel the postscribe load if my component unmounts before the script is loaded. Why? Because React will complain, rightly so, if I try and do things with an unmounted component because in some cases, when the afterAsync callback is called, the component is gone. I need to cancel it from triggering, naturally I'd want to cancel it within my componentWillUnmount hook.
Looking into the documentation, it looks like
postscribe(...)
returns an object that you can call.cancel()
on. So I did that, but the error I get is:args.stream.abort is not a function
This is referring to the
WritableStream
class and looking into it, I couldn't see anywhere that anabort()
method exists.Here is how I'm using the code in a React component in componentDidMount I call this:
this.el is an element reference from the DOM. After the script loads, I want to show the element so that's why I call setState.
Then, to properly cancel this loading, I presumed I could do this:
But when that fires, I get this error in the JS console:
Uncaught TypeError: args.stream.abort is not a function
That cancel function from the postscribe code is here:
https://github.com/krux/postscribe/blob/master/src/postscribe.js#L172
and for easy reference looks like this:
So I guess my ultimate question is, if abort() doesn't really exist on the WritableStream object, is there any other suggestion on how I can cancel to stop the afterAsync from triggering when the component is unmounted before the postscribe script loads.
The text was updated successfully, but these errors were encountered: