我看到了一些这样的示例代码:

import React from 'react'
import MyComp from 'my-comp'

const MySubComp = MyComp.MySubComp

class Page extends React.Component {
  render() {
    return (
      <MyComp>
        <MySubComp/>
      </MyComp>
      )
  }
}

如何实现MyComp.MySubComp语法?

有术语吗?

最佳答案

在您的示例中,MySubCompMyComp的静态类成员,您可以像这样轻松实现它:

export default class MyComp extends Component {
   // ...
}

MyComp.MySubComp = class MySubComp extends Component {
   // ...
}

关于reactjs - React : How to implement Component.子组件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41156119/

10-12 14:05