我想创建这个组件的新实例,并想要为新实例更改标题desc和image,但我收到错误
错误:
ReferenceError:未定义产品
function Ads(product) {
return(
<div className = "row" id="user-ads">
<div className = "col-sm-6 col-md-5">
<div className = "thumbnail">
<img src = "img/img1.jpg" alt = "Generic placeholder thumbnail" />
</div>
<div className = "caption">
<div className="border">
<h3>{product.title}</h3>
<p>{product.desc}</p>
<button className = "btn btn-primary" role = "button" data-toggle="modal" data-target="#view-detail">View Details
</button>
</div>
</div>
</div>
</div>
);
}
var Newad = new Ads(product);
答案 0 :(得分:1)
那不是React组件。这是编写组件的一种方法。有ES6语法,但我不打算发布它,因为它可能会让你感到困惑。
// Include React
var React = require('react');
var Ads = React.createClass({
render: function(){
return(
<div>
<h1>I'm a Ad!</h1>
</div>
)
}
});
module.exports = Ads;