Wie füge ich beim Klicken auf die Schaltfläche die Komponente "Reagieren" hinzu?

Ich hätte gerne einAdd input Schaltfläche, die beim Klicken neues @ hinzufüInput Komponente. Das Folgende ist der Code von React.js, von dem ich dachte, dass er eine Möglichkeit ist, die gewünschte Logik zu implementieren, aber leider funktioniert er nicht.

Die Ausnahme, die ich habe, ist:invariant.js:39 Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {input}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `FieldMappingAddForm`.

Wie löse ich dieses Problem?

import React from 'react';
import ReactDOM from "react-dom";


class Input extends React.Component {
    render() {
        return (
            <input placeholder="Your input here" />
        );
    }
}


class Form extends React.Component {
    constructor(props) {
        super(props);
        this.state = {inputList: []};
        this.onAddBtnClick = this.onAddBtnClick.bind(this);
    }

    onAddBtnClick(event) {
        const inputList = this.state.inputList;
        this.setState({
            inputList: inputList.concat(<Input key={inputList.length} />)
        });
    }

    render() {
        return (
            <div>
                <button onClick={this.onAddBtnClick}>Add input</button>
                {this.state.inputList.map(function(input, index) {
                    return {input}   
                })}
            </div>
        );
    }
}


ReactDOM.render(
    <Form />,
    document.getElementById("form")
);

Antworten auf die Frage(2)

Ihre Antwort auf die Frage