Vishnu Shekhawat Vishnu Shekhawat - 2 months ago 8
React JSX Question

Subcomponent in React ES6

I know that in Past version of React we can make subcomponent like this.

var MyFormComponent = React.createClass({ ... });

MyFormComponent.Row = React.createClass({ ... });
MyFormComponent.Label = React.createClass({ ... });
MyFormComponent.Input = React.createClass({ ... });


But i want to know how we can create subcomponent in React ES6.
is it using syntax like

class Row Extends MyFormComponent , Component {}


or is there other way round for this approach?

Answer

I think the syntax you are looking for is:

MyFormComponent.Row = class Row extends React.Component { ... }

As @Borjante commented, though, this is just a way to group components under another component, and there is no special "subcomponent" behavior about any of this. If you think it's a good pattern for naming components, though, then go for it.

Comments