๐๐ฏ๐ผ๐ฟ๐๐ถ๐ป๐ด ๐ผ๐ป๐ด๐ผ๐ถ๐ป๐ด ๐ฎ๐ฐ๐๐ถ๐๐ถ๐๐ถ๐ฒ๐ ๐๐๐ถ๐ป๐ด ๐๐ต๐ฒ ๐๐ฏ๐ผ๐ฟ๐๐๐ผ๐ป๐๐ฟ๐ผ๐น๐น๐ฒ๐ฟ ๐ถ๐ป๐๐ฒ๐ฟ๐ณ๐ฎ๐ฐ๐ฒ.
The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort it if required via an AbortController object.
๐. ๐๐๐๐ป๐ฐ ๐๐ผ๐ฟ๐ธ ๐ถ๐ป ๐ฅ๐ฒ๐ฎ๐ฐ๐:
Let's take the example of data fetching placed inside a useEffect hook.
If this effect doesn't finish before it's fired again (re-render), we may have two requests running in parallel.
To make things better, we can create an AbortController instance that will be aborted whenever the next effect runs.
๐๐ฉ๐ฆ๐ฏ ๐ข๐ฃ๐ฐ๐ณ๐ต() ๐ช๐ด ๐ค๐ข๐ญ๐ญ๐ฆ๐ฅ, ๐ต๐ฉ๐ฆ ๐ง๐ฆ๐ต๐ค๐ฉ() ๐ฑ๐ณ๐ฐ๐ฎ๐ช๐ด๐ฆ ๐ณ๐ฆ๐ซ๐ฆ๐ค๐ต๐ด ๐ธ๐ช๐ต๐ฉ ๐๐๐๐๐น๐ค๐ฆ๐ฑ๐ต๐ช๐ฐ๐ฏ ๐ฏ๐ข๐ฎ๐ฆ๐ฅ ๐๐ฃ๐ฐ๐ณ๐ต๐๐ณ๐ณ๐ฐ๐ณ.
๐. ๐ฅ๐ฒ๐บ๐ผ๐๐ถ๐ป๐ด ๐๐๐ฒ๐ป๐ ๐๐ฎ๐ป๐ฑ๐น๐ฒ๐ฟ๐:
To remove an event handler, you have to keep hold of the original reference.
Using AbortSignal, you can get the signal to remove it for you.
Promise-based APIs wishing to support aborting can accept an AbortSignal object, and use its state to determine how to proceed (https://bit.ly/3HB3hjQ).
Top comments (0)