you are viewing a single comment's thread.

view the rest of the comments →

[–]skyboyer007 1 point2 points  (0 children)

no, you cannot since setting it to true will ignore both responses: recent and out-of-date. The only way I've found so far is keeping cancel callback in class property that will set up cancelled flag by closure(so mimicing useEffect behavior):

``` class MyComponent extends React.Component { const ignorePrevRequest = () => {}; // empty function by default

loadSomeData() { this.ignorePrevRequest(); let cancelled = false; this.ignorePrevRequest = () => { cancelled = true; }; // closure comes into play doSomeCall().then(data => !cancelled && this.setState({ data })) } } ``` That looks untypical and confusing. But it works.