What this error is in ReactJS

1

This is the code

render() {
    this.customize();

    return (<ReactF1
      id="ResponsiveHeader"
      data-f1="header" 
    >
      <h1>Hola</h1>
    </ReactF1>);
  }

And this the error:

  

Unexpected token, expected;
  line 6, column 10
  Work / src / components / header / index.js

I guess it will be for some syntax but no idea.

    
asked by Santiago D'Antuoni 09.01.2017 в 17:20
source

1 answer

2

The problem is that you are using invalid syntax. I think your intention was to use a class since you mention that you are using import it is very likely that you have support for classes as well.

Your render method would be a method of the class and the class the component as such.

import React, { Component} from 'react';

class MiComponente extends Component {
  render() {
     this.customize();
     return ( 
       <ReactF1 id="ResponsiveHeader" data-f1= "header" >
         <h1>Hola</h1>
       </ReactF1>
     );
  }
}

export default MiComponente;

Read link

I do not know what the this.customize() function is, but it seems to me that what you are creating is a presentation component, so you should not include another code in the render function unless it is needed by a library.

Read link

If you are not using ES6 you should use this syntax where the render method is a property of an object

var MiComponente = React.createClass({
  render: function() {
    return (
      <ReactF1 id="ResponsiveHeader" data-f1="header">
         <h1>Hola</h1>
      </ReactF1>
    )
  }
});

Read link

If you notice the declaration render must carry the identifier function , since it is a function or be a member of a class of ES6 not to take it.

    
answered by 09.01.2017 / 18:11
source