请问老师是这样吗?
来源:7-5 扩展作业

FishKylin
2020-05-12
import React from 'react';
// 模拟请求
const requestHttp = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, 3000);
}).then(data => {
return data;
});
}
const widthLoading = (Component) => {
return class extends React.Component {
constructor(props) {
super(props);
this.state = {
data: false
}
}
componentDidMount() {
requestHttp().then(res => {
this.setState({
data: res
});
})
}
render() {
return this.state.data ?
<Component {...this.props} data={this.state.data} />
:
<div>loading</div>
}
}
}
export default widthLoading;
写回答
1回答
-
张轩
2020-05-14
同学你好 写的很不错 命名有点小问题:widthLoading, 应该是 withLoading。
00
相似问题