lilytly123 lilytly123 - 8 days ago 5
React JSX Question

a Reactify Error :Unexpected identifier



var React = require('react');
var EventListItem = require('./EventListItem.js');

var EventList = React.createClass({
var events = this.props.events;
if (!Array.isArray(events)) throw new Error ('it must be Array');
var eventsComps = events.map(function(eve){
return (<EventListItem key={eve.key}
title={eve.title}
description={eve.description}
voteCount={eve.voteCount} />)
});

render:function(){
return(
<div id="events" className="">

{eventsComps}

</div>
);
}
});

module.exports = EventList;





Line 5: Unexpected identifier
I search the problem and checked my ","or ";"but I don't find the problem,what's wrong with it?

Answer

You cannot write any random statements inside an object literal. All you code need to be inside you render function or you must define a different function and write this code inside it.

var React = require('react');
var EventListItem = require('./EventListItem.js');

var EventList = React.createClass({

    render:function(){
            var {events} = this.props;
        if (!Array.isArray(events)) throw new Error ('it must be Array');
           var eventsComps = events.map(function(eve){
           return (<EventListItem key={eve.key}
           title={eve.title}
           description={eve.description}
           voteCount={eve.voteCount} />)
        });
        return(
            <div id="events" className="">

                {eventsComps}

            </div>
        );
    }
});

module.exports = EventList;