class Example extends React.Component {
state = { data: [] };
controller = new AbortController();
componentDidMount() {
fetch('/url', {
signal: this.controller.signal,
})
.then(res => res.json())
.then(data => this.setState({ data }));
}
componentWillUnmount() {
this.controller.abort();
}
render(){
return ( /* ... */ );
}
}