React: How to implement Component.SubComponent

I saw an example code like this:

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

const MySubComp = MyComp.MySubComp

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

How to implement the syntax MyComp.MySubComp?

Does he have terminology?

+4
source share
1 answer

In your example, MySubCompis a static member of a class MyComp, you can easily implement it as follows:

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

MyComp.MySubComp = class MySubComp extends Component {
   // ...
}
+6
source

Source: https://habr.com/ru/post/1663797/


All Articles