如何解决我的 jsx 中的意外令牌错误?

How to solve the unexpected token error in my jsx?

我正在使用 reactjs,这是我的组件代码的一部分:

  myType() {
        return myComponent;
  }
  render() {
              return (
                <div className="row">
                    {
                       let thisType = this.myType;
                       return (<thisType />)
                    }
                </div>
            );
  }

当我 运行 我的代码时,我得到这个错误:

BabelLoaderError: SyntaxError: ../.../myComponent.js: Unexpected token (47:19

这是指向let语句?

为什么不试试

<div className='row'>
   { this.myType() }
</div>

你应该获取 JSX 之外的组件名称,并将其放在首字母大写的变量中(这是 JSX 确定它是否为自定义组件的方式):

myType() {
    return myComponent;
}

render() {
    let ThisType = this.myType();

    return (
        <div className="row">
            <ThisType />
        </div>
    );
}