admin管理员组文章数量:1335624
i use react 16, babel 7, webpack 4.
another project is working, but this project is not working. error is (intermediate value).then is not a function . i don't know what is problem... umm.. how to solve this problem? please help me.
import React, { Component } from 'react';
// import throttle from 'lodash.throttle'
import debounce from 'lodash.debounce';
class Promise extends Component {
constructor() {
super();
// this.handleDebounce = this.handleDebounce.bind(this);
}
handleDebounce = (e) => {
// debounce(this.handleStart, 100); // 이런식으로 쓰면 안된다!! SyntheticEvent pooling (이벤트 풀링) 참고 .html#event-pooling
// 콜백함수는 해당 이벤트가 실행되는 동안에만 유효함
this.setSearchTerm(e.target.value);
}
setSearchTerm = debounce((searchTerm) => this.handleStart(searchTerm), 2000);
handleStart = (value) => {
console.log("start", value)
this.handlePromise1(value)
.then(text => {
console.log(text)
})
.catch((err) => {console.log("err", err)})
}
handlePromise1 = (value) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
this.handlePromise2(resolve(value));
}, 300);
});
}
handlePromise2 = (value) => {
return new Promise((resolve, reject) => {
resolve(value);
});
}
render() {
return (
<div>
<input onKeyUp={this.handleDebounce}></input>
</div>
);
}
}
export default Promise;
i use react 16, babel 7, webpack 4.
another project is working, but this project is not working. error is (intermediate value).then is not a function . i don't know what is problem... umm.. how to solve this problem? please help me.
import React, { Component } from 'react';
// import throttle from 'lodash.throttle'
import debounce from 'lodash.debounce';
class Promise extends Component {
constructor() {
super();
// this.handleDebounce = this.handleDebounce.bind(this);
}
handleDebounce = (e) => {
// debounce(this.handleStart, 100); // 이런식으로 쓰면 안된다!! SyntheticEvent pooling (이벤트 풀링) 참고 https://reactjs/docs/events.html#event-pooling
// 콜백함수는 해당 이벤트가 실행되는 동안에만 유효함
this.setSearchTerm(e.target.value);
}
setSearchTerm = debounce((searchTerm) => this.handleStart(searchTerm), 2000);
handleStart = (value) => {
console.log("start", value)
this.handlePromise1(value)
.then(text => {
console.log(text)
})
.catch((err) => {console.log("err", err)})
}
handlePromise1 = (value) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
this.handlePromise2(resolve(value));
}, 300);
});
}
handlePromise2 = (value) => {
return new Promise((resolve, reject) => {
resolve(value);
});
}
render() {
return (
<div>
<input onKeyUp={this.handleDebounce}></input>
</div>
);
}
}
export default Promise;
Share
Improve this question
asked Nov 19, 2018 at 2:06
kekeeekekeee
4752 gold badges7 silver badges14 bronze badges
2
-
1
class Promise extends Component
... are you sure you want to overridePromise
?return new Promise
... will return a new instance of yourclass Promise
- which has no.then
method – Bravo Commented Nov 19, 2018 at 2:14 - oh my god..... thank you... – kekeee Commented Nov 19, 2018 at 5:11
1 Answer
Reset to default 3Solution: (edit 1)
The issue was not because of async but because of overriding Promise on browser. The new Promise() doesn't actually create the expected promise. Check here
No async Needed as I mentioned before this edit as below:
Stale answer (not right): just for reference: I think that issue was a missing async during declaration of handlePromise1. Because it signifies that the function is asynchronous and may return a Promise as a return value. if not specified it would treat it as any object and .then might not be available.
I just added async and found it to be working in this code
Also,the ment by @bravo is valid. You should not try to override Promise in any JS code
本文标签: javascriptTypeError (intermediate value)then is not a functionStack Overflow
版权声明:本文标题:javascript - TypeError: (intermediate value).then is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315159a2451668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论