0

I'm trying to call component in render function, when the data is ready, or return null. I don't know why, but react-rails gem return Parse Error in this string. Source code is below:

var PlayersData = React.createClass({

  loadDataFromServer: function() {
    console.log("loadDataFromServer");
    $.ajax({
      url: this.props.url,
      dataType: 'json',
      success: function(data) {
        this.setState({data: data});
      }.bind(this),
      error: function(xhr, status, err) {
        console.error(this.props.url, status, err.toString());
      }.bind(this)
    });
  },

  getInitialState: function() {
    console.log("getInitialState");
    return {data: {}};
  },

  componentWillMount: function() {
    console.log("componentWillMount");
    this.loadDataFromServer();
  },

  render: function() {
    console.log("render");
    return (
      {this.state.data ? : <PlayersRepresentation data={this.state.data} /> : null}
    );
  }
});

Error trace log:

Showing /Users/user/Documents/Projects/rails_react/app/views/layouts/application.html.erb where line #12 raised:

Error: Parse Error: Line 30: Unexpected token .
  (in /Users/user/Documents/Projects/rails_react/app/assets/javascripts/components/match_center/players_data.js.jsx)

How does fix it?

nilgun
  • 10,460
  • 4
  • 46
  • 57
MaxH
  • 11
  • 3

1 Answers1

0

This colon doesn't belong:

 //                 V
 {this.state.data ? : <PlayersRepresentation data={this.state.data} /> : null}

If you remove that, does it parse correctly?

rmosolgo
  • 1,854
  • 1
  • 18
  • 23