React:如何实现Component.SubComponent

时间:2016-12-15 03:48:22

标签: reactjs

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

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

是否有术语?

1 个答案:

答案 0 :(得分:11)

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

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

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