Reputation: 25
I'm learning react and can create components in different js files. But I would like to know if there is a way to create Main
class with sub1
and sub2
components. And call components like this
import Main from './dir/main';
export default class Settings extends React.Component {
render () {
return (
<div>
<Main.sub1>
<Main.sub2/>
</div>
)
}
}
Upvotes: 1
Views: 26
Reputation: 266
I think you can try something like that because you have an instance so you have to surround it
import Main from './dir/main';
import React from 'react';
export default class Settings extends React.Component {
render () {
return (
<>
<div>
<Main.sub1 />
<Main.sub2 />
</div>
</>
)
}
}
Upvotes: 1