React:无法获取组件列表
React: Can't get a list of component
在我的反应中 class 我尝试将一个 Row 组件添加到列表中,以供以后需要列出一些内容时使用。它 returns 我那个错误:
Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it
在另一个项目中,我有相同的功能,但它的工作原理不同。
我使用 WebPack 和 reactstrap
行。
我的class
import React, { Component } from 'react';
import {Row, Col, Container} from 'reactstrap';
class Test extends Component {
constructor(props) {
super(props);
this.insert = this.insert.bind(this);
}
insert() {
var list = [];
list.push(
<Row>
<Col>
<p>Test data</p>
</Col>
</Row>);
return {list};
}
render() {
return (
<div>
<Container>
{this.insert}
</Container>
</div>
);
}
}
export default Test;
你可以试试这个
import React, { Component } from "react";
import { Row, Col, Container } from "reactstrap";
class MyComponent extends Component {
insert() {
var list = [];
list.push(
<Row>
<Col>
<p>Test data</p>
</Col>
</Row>
);
return list;
}
render() {
return (
<div>
<Container>{this.insert()}</Container>
</div>
);
}
}
export default MyComponent;
在我的反应中 class 我尝试将一个 Row 组件添加到列表中,以供以后需要列出一些内容时使用。它 returns 我那个错误:
Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it
在另一个项目中,我有相同的功能,但它的工作原理不同。
我使用 WebPack 和 reactstrap
行。
我的class
import React, { Component } from 'react';
import {Row, Col, Container} from 'reactstrap';
class Test extends Component {
constructor(props) {
super(props);
this.insert = this.insert.bind(this);
}
insert() {
var list = [];
list.push(
<Row>
<Col>
<p>Test data</p>
</Col>
</Row>);
return {list};
}
render() {
return (
<div>
<Container>
{this.insert}
</Container>
</div>
);
}
}
export default Test;
你可以试试这个
import React, { Component } from "react";
import { Row, Col, Container } from "reactstrap";
class MyComponent extends Component {
insert() {
var list = [];
list.push(
<Row>
<Col>
<p>Test data</p>
</Col>
</Row>
);
return list;
}
render() {
return (
<div>
<Container>{this.insert()}</Container>
</div>
);
}
}
export default MyComponent;