1

I'll be very grateful who can help me with this line I've this:

 var Country = React.createClass({
        render:function(){
            return(
                <nav> 
                <h2>list of country:</h2>
                { this.props.country}
                </nav>
            )
        }
    }) 
    var Jugador =React.createClass({
          componentWillMount: function(){
                var pais;
                var self = this;
                $.getJSON("https://restcountries.eu/rest/v1/all", function(data){
                    for(pais in data)
                    {
                        console.log(pais, data[pais].name);

                        return(
                            <Country key={i} country={self.render(data[pais].name)}> </Country>
                        )
                    }
                })
          },
    })

and it does not work, and appear this error Uncaught Invariant Violation: createClass(...): Class specification must implement a render method.

1
  • Jugador doesn't have a render method. Is it a react component? Commented Mar 14, 2016 at 12:14

2 Answers 2

1

Your Jugador component needs to implement a render method.

Sign up to request clarification or add additional context in comments.

Comments

0

In React each component must have render method, you should implement it. I've refactored your code and now it look like this

var Country = React.createClass({
  render: function() {
    return <div> 
      { this.props.country }
    </div>
  }
})

var Countries = React.createClass({
  getInitialState: function () {
    return { countries: [] };
  },

  componentWillMount: function(){
    $.getJSON("https://restcountries.eu/rest/v1/all", function (data) {
      this.setState({ countries: data })
    }.bind(this))
  },

  render: function () {
    var countries = this.state.countries.map(function (el, i) {
      return <Country key={i} country={ el.name } />
    }, this);

    return <nav>
      <h2>list of country:</h2>
      <div>{ countries }</div>
    </nav>;
  }       
})

Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.