ReactJs create Namespaced components

A namespace(name scope) holds the grouping of unique identifiers or names, this identifiers associated only with the appropriate namespace.

You have created some components with many children like below.

var Form1 = React.createClass({...});
var Form2 = React.createClass({...});
var Form3 = React.createClass({...});
var Form4 = React.createClass({...});

Here components created as a variable declaration. Now create one namespace variable to make it simple.

var FormComponents = FormComponents || {};

This is the method for creating namespace/Object.

FormComponent.Form1 = React.createClass({...});
FormComponent.Form2 = React.createClass({...});
FormComponent.Form3 = React.createClass({...});
FormComponent.Form4 = React.createClass({...});

This feature is available in v0.11 and above.

Leave a Reply

Your email address will not be published. Required fields are marked *