Реагировать: не могу получить список компонентов - PullRequest
0 голосов
/ 22 ноября 2018

В моем классе реакции я пытаюсь добавить компонент Row в список на потом, когда мне нужно будет перечислить некоторые вещи.Это возвращает мне эту ошибку:
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 для строки.

Мой класс

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;

1 Ответ

0 голосов
/ 22 ноября 2018

Вы можете попробовать это

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;

https://codesandbox.io/embed/j2pm2q1499

...