1

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>
        )
    }
}

1 Answer 1

1

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>
          </>
        )
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, butu I don't know how to customize Main class
You could try to add props : like : this.props.name and after <Main name="Shaben" /> actually this is an example but you can to modify to be better and pass lots of args
or try with this.state.value depends what do you want to do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.