React: Export Module

(Last Updated On: )

Sometimes we need exportable modules for use through our applications. It is pretty straight forward to export a module.

NPM Installs:

  1. npm install create-react-class --save
  2. npm install prop-types --save
  3. npm install react --save
  4. npm install react-dom --save

Export:

  1. module.exports = {exportedModuleName:ModuleName};

exportedModuleName is the name that you use in other pages.
ModuleName is the name of the module to export.

The module will look something like this.
This one is just a TD module. But really you can do anything you want.

  1. window.jQuery = window.$ = require("jquery");
  2. import React from "react";
  3. import ReactDOM from "react-dom";
  4. var createReactClass = require('create-react-class');
  5. var propTypes = require('prop-types');
  6.  
  7. var MyExportableModule = createReactClass({
  8.       render: function() {
  9.             return React.createElement("anyelement", {className: this.props.className, key: this.props.name}, this.props.fields);
  10.       }
  11. });
  12.  
  13. MyExportableModule.PropTypes = {
  14.       name: React.PropTypes.string.isRequired,
  15.       fields: React.PropTypes.array.isRequired,
  16.       className: React.PropTypes.string
  17. };