1

Having some weird situation at least weird for me. I'm building timeline component so far so good. In case user timeline is empty i want to render different react class Here a portion of the code i did

var Timeline = React.createClass({
getInitialState: function() {
    return {
        data: [],
        page: 0,
        loadingFlag: false
    }
},
loadTimelineFromServer: function() {
    var nextPage = this.state.page + 1;
    var url = this.props.url + '?page=' + nextPage;
    $.ajax({
        url: url,
        dataType: 'json',
        cache: true,
        success: function(response) {
            if (this.isMounted()) {
                this.setState({
                    data: this.state.data.concat(response.data),
                    loadingFlag: false,
                    page: nextPage
                });
            }
        }.bind(this),
        error: function(xhr, status, err) {
            console.error(this.props.url, status, err.toString());
        }.bind(this)
    });
},
componentDidMount: function() {
    this.loadTimelineFromServer();
},
render: function() {
    var items = this.state.data;
    var renderer;
    if (items.length) {
        renderer = <TimelineList data=items />
    } else {
        renderer = <EmptyTimeline />
    }

    return (
        <div>
        {renderer}
        </div>
    );
} 
});

EDIT : the error fired from firebug Error: Parse Error: Line 71: JSX value should be either an expression or a quoted JSX text at http://qfriends.dev/js/components/socialnetwork/user_timeline.js:71:20 ...pointing to this <TimelineList data=items />

2
  • worth mentioning i followed steps from reactjs docs page facebook.github.io/react/tips/if-else-in-JSX.html Commented Jun 24, 2015 at 11:47
  • What's not working? Do you see anything at all? Do you get any errors? A bit more information would be helpful. Commented Jun 24, 2015 at 11:55

2 Answers 2

2

<TimelineList data=items /> is not valid JSX. You should use curly braces to pass a javascript expression as a prop: <TimelineList data={items} />.

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

1 Comment

Thanks i almost forgot about this rule! U saved my day :)
0

You should add either a semicolon to the end:

if (items.length) {
    renderer = <TimelineList data=items />;
} else {
    renderer = <EmptyTimeline />;
}

or do it like this:

if (items.length) {
    renderer = (
        <TimelineList data=items />
    );
} else {
    renderer = (
        <EmptyTimeline />
    );
}

1 Comment

thanks for your time sir! Really appreciate the efforts

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.