Cancelling ongoing http requests when next one is started - web app search feature
You can rewritte this piece of code:

.catch(error =&gt; {
    if (
    cts !== 'undefined' &amp;&amp;
    cts.token !== 'undefined' &amp;&amp;
    cts.token.reason !== 'undefined' &amp;&amp;
    cts.token.reason.message === 'next request started'
    ) {
    } else {
    throw error;
    }
}


To:

.catch(error =&gt; {
    if (
        typeof cts === 'undefined' ||
        typeof cts.token === 'undefined' ||
        typeof cts.token.reason === 'undefined' ||
        cts.token.reason.message !== 'next request started'
    ) {
        throw error;
    }
}


And you can go further into the simplification using this trick.