如何解决React Rails如何在PropTypes中使用状态
我正在尝试通过搜索创建简单列表,但是在使用状态时遇到问题。当我添加构造函数时,该程序无法正常工作。也许我需要以其他方式从Rails传输数据,但是如何?我该怎么办?
Label.js:
import React from "react"
import PropTypes from "prop-types"
class ProductRow extends React.Component {
render() {
return (
<tr>
<td>{this.props.product}</td>
<td>{this.props.body}</td>
<td>{this.props.price}</td>
</tr>
);
}
}
class ProductTable extends React.Component {
render() {
const rows = [];
rows.push(
<ProductRow
product={this.props.name}
price={this.props.price}
body={this.props.body}
key={this.props.id}
/>
);
return (
<table>
<thead>
<tr>
<th>Name</th>
<th>Body</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{rows}</tbody>
</table>
);
}
}
class Label extends React.Component {
render () {
return (
<React.Fragment>
{<ProductTable name = {this.props.label} price = {this.props.price} id ={this.props.id} body = {this.props.body} /> }
</React.Fragment>
);
}
}
Label.propTypes = {
id: PropTypes.number,label: PropTypes.string,price: PropTypes.number,body: PropTypes.string,};
export default Label
有我的rails代码:
<%= react_component("Label",{ label: product.title,price: product.price,body: product.body,id:product.id,}) %>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。