How to create another component and use it in ComponentA?
There are two possible ways to do this:
1 - Define the component in the same file, you will not need to export this component because you will use this component in the same file.
2 - Define the component in another file, then export this component. Component import will be necessary in this case.
We can create as many components as we want in one file, and we can use these components in the same way as we use HTML tags div, span, p , etc.
Example:
Using ComponentB inside another ComponentA component:
export default class ComponentA extends components { render(){ return( <div> {/*other code*/} <ComponentB /> // notice here, rendering ComponentB </div> ) } }
Define ComponentB in the same file:
class ComponentB extends components { }
Define ComponentB like this in another file:
export default class ComponentB extends components { }
source share