Rx fromPromise 没有将 then 识别为函数?
Rx fromPromise not recognizing then as a function?
我正在尝试在 react
组件中使用 rx-lite
。我正在传递 Rx.Observable.fromPromise
一个 axios
http 请求。 axios
returns a promise
所以它应该找到 .then
。这是我的组件。
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
results: []
}
this.handleOnBlur = this.handleOnBlur.bind(this);
this.handleOnBlurDebounced = this.handleOnBlur.debounce(250, false);
this.getResults = this.getResults.bind(this);
}
componentDidMount() {
this.subscription = Rx.Observable.fromPromise(this.getResults)
.map(res => this.setState({
results: res.data.return
}));
}
componentWillUnmount() {
this.subscription.dispose();
}
getResults() {
return axios.get('/results');
}
handleOnBlur() {
this.subscription.forEach();
}
render() {
...
}
}
在我的 componentDidMount
中,我调用 this.getResults
。我收到此错误。
Uncaught TypeError: this._p.then is not a function
如果我使用 this.getResults()
,它会进行调用,但不是懒惰的。我需要更改什么才能使这项工作正常进行?
In my componentDidMount, I call this.getResults
不,如果您不使用 this.getResults()
,您就不会调用它。 fromPromise
采用承诺,而不是您传递的承诺返回函数。
我正在尝试在 react
组件中使用 rx-lite
。我正在传递 Rx.Observable.fromPromise
一个 axios
http 请求。 axios
returns a promise
所以它应该找到 .then
。这是我的组件。
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
results: []
}
this.handleOnBlur = this.handleOnBlur.bind(this);
this.handleOnBlurDebounced = this.handleOnBlur.debounce(250, false);
this.getResults = this.getResults.bind(this);
}
componentDidMount() {
this.subscription = Rx.Observable.fromPromise(this.getResults)
.map(res => this.setState({
results: res.data.return
}));
}
componentWillUnmount() {
this.subscription.dispose();
}
getResults() {
return axios.get('/results');
}
handleOnBlur() {
this.subscription.forEach();
}
render() {
...
}
}
在我的 componentDidMount
中,我调用 this.getResults
。我收到此错误。
Uncaught TypeError: this._p.then is not a function
如果我使用 this.getResults()
,它会进行调用,但不是懒惰的。我需要更改什么才能使这项工作正常进行?
In my componentDidMount, I call
this.getResults
不,如果您不使用 this.getResults()
,您就不会调用它。 fromPromise
采用承诺,而不是您传递的承诺返回函数。