Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactDOM.render Expected the last optional `callback` argument to be a function

I am new to react and I wrote the code below and got

ReactDOM.render Expected the last optional `callback` argument to be a function. `Instead received: Object` 

This is my code

var Stats = React.createClass({
    render: function () {
        return (
            <article className="col-md-4">
                <article className="well">
                    <h3>{this.props.value}</h3>
                    <p>{this.props.label}</p>
                </article>
            </article>
        )
    }
});

ReactDOM.render(
    <Stats value={"255.5K"} label={"People engaged"}/>,
    <Stats value={"5K"} label={"Alerts"}/>,
    <Stats value={"205K"} label={"Investment"}/>,
    document.getElementById('stats')
);

What am I doing wrong?

like image 331
elad silver Avatar asked Sep 11 '26 17:09

elad silver


1 Answers

You are giving ReactDom.render four arguments - three Stats components and the element. The function expects only one element before the container element. Thus you need to somehow group the elements together, for example like this:

ReactDOM.render(
  <div>
    <Stats value={"255.5K"} label={"People engaged"}/>
    <Stats value={"5K"} label={"Alerts"}/>
    <Stats value={"205K"} label={"Investment"}/>
  </div>,
  document.getElementById('stats')
);
like image 64
Waiski Avatar answered Sep 13 '26 13:09

Waiski