Skip to content

Cannot parse HTML to JSX without using outputClassName #21

@alansouzati

Description

@alansouzati

Hi,

Great job on react-magic. I'm trying to use this component with the following option:

{
   createClass: true
}

I would expect the following output:

"React.createClass..."

but it turns out to be

"var NewComponent = React.createClass...."

I see in the code that the config outputClassName is optional. In the convert function we have:

  if (this.config.createClass) {
      if (this.config.outputClassName) {
        this.output = 'var ' + this.config.outputClassName + ' = React.createClass({\n';
      } else { // this is the callback i was expecting to be called
        this.output = 'React.createClass({\n';
      }
      this.output += this.config.indent + 'render: function() {' + "\n";
      this.output += this.config.indent + this.config.indent + 'return (\n';
 }

But in the object constructor there is always a fallback to 'NewComponent', from the source-code:

var HTMLtoJSX = function(config) {
  this.config = config || {};

  if (this.config.createClass === undefined) {
    this.config.createClass = true;
  }
  if (!this.config.indent) {
    this.config.indent = '  ';
  }
  if (!this.config.outputClassName) { // I would not expect to have this line in place.
    this.config.outputClassName = 'NewComponent';
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions