return 报错

来源:3-11 自定义 Hook 第二部分 - HOC的劣势

Aicheng123

2020-05-06

Parsing error: Unexpected token

11 | }
12 | const withLoader =

(WrappedComponent: React.ComponentType

, url: string) => {

13 | return class LoaderComponent extends React.Component<Partial, ILoaderState> {
| ^
14 | constructor(props: any) {
15 | super(props)
16 | this.state = {

如上return 报错

写回答

2回答

张轩

2020-05-08

同学你好 使用你贴给我的代码并没有报错 请检查用法是否有误 本节源代码在这里:

https://git.imooc.com/coding-428/react-with-ts/commit/f82a24100fad1a9d1d6274353ef1012002d712e3

0
0

张轩

2020-05-06

同学你好 能把你的全部代码贴一下吗 这样看一部分错误代码 没法很好的发现问题 谢谢

0
1
Aicheng123
const withLoader =

(WrappedComponent: React.ComponentType

, url: string) => { return class LoaderComponent extends React.Component, ILoaderState> { constructor(props: any) { super(props) this.state = { data: null, isLoading: false } } componentDidMount() { this.setState({ isLoading: true, }) axios.get(url).then(result => { this.setState({ data: result.data, isLoading: false }) }) } render() { const { data, isLoading } = this.state return ( <> { (isLoading || !data) ?

data is loading

: } ) } } } 如上return处有报错
2020-05-06
共1条回复

React18+TS高仿AntD从零到一打造组件库

设计,开发,测试,发布再到 CI/CD,从0到1造轮子

2122 学习 · 959 问题

查看课程