new Promise((resolve, reject) => {
                  
                  
                      promise.then(result => (
                  
                  
                        isCanceled() ? reject() : resolve(result)
                  
                  
                      ));
                  
                  
                    });
                  
                  
                  
                  
                  
                  class Test extends React.Component {
                  
                  
                    
                  
                  
                    ...  
                  
                  
                    
                  
                  
                    componentDidMount() {
                  
                  
                      this.isMounted_ = true;
                  
                  
                    }
                  
                  
                  
                  
                  
                    componentWillUnmount() {
                  
                  
                      this.isMounted_ = false;
                  
                  
                    }
                  
                  
                  
                  
                  
                    test() {
                  
                  
                      getCancellablePromise(
                  
                  
                        this.props.someAction(),
                  
                  
                        () => !this.isMounted_
                  
                  
                      ).then(
                  
                  
                        () => {
                  
                  
                          // make smth        
                  
                  
                        },
                  
                  
                        () => { /* canceled */ }
                  
                  
                      );    
                  
                  
                    }  
                  
                  
                    ...
                  
                  
                    
                  
                  
                  }
                  
                  
                
второй парам точно isCancelled?)
ты же не знаешь его состояние при создании обёрнутого промиса
Обсуждают сегодня