Component - AbortController for cancellation
This React Native component demonstrates how to use AbortController to cancel a fetch request. It shows a button to start loading data and another to cancel the request if it is still in progress.
This React Native component demonstrates how to use AbortController to cancel a fetch request. It shows a button to start loading data and another to cancel the request if it is still in progress.
View ├── Text ├── Button (Start Fetch) └── Button (Cancel Fetch)
AbortController in React Native fetch requests?new AbortController().signal and its value is controller.signal.const controller = new AbortController();
fetch('https://example.com/data', { signal: controller.signal })
.then(response => response.json())
.then(data => console.log('Data:', data))
.catch(error => console.log('Error:', error.name));
controller.abort();
What will be logged to the console?const controller = new AbortController();
fetch('https://api.example.com', { signal: controller.signal });
// Some code
controller.abort();
What is the most likely reason the fetch is not canceled?Pass the test and this pattern moves unknown