score:0

you can map through an array of your objects:

constructor(props) {
        super(props);
        this.state = {
            task: '',
            count: [1],
            components: []
        };
        this.addtask = this.addtask.bind(this);
        this.change = this.change.bind(this);
    }

    render() {
        return (
            <div>
                <h1>form</h1>
                <form onsubmit = {this.onsubmit} method='post'>
                    <div>
                        {this.state.count.map((item, index) => {
                            return (
                                <div key={index}>
                                    {this.state.components.map(comp => comp)}
                                </div>
                            )
                        })}
                    </div>

                    <button onclick={this.addtask}>addtask</button>
                    <button>submit</button>
                </form>
            </div>
        );
    }

    addtask(e) {
        e.preventdefault();
        this.setstate({
            count: [...this.state.count, '1'],
            components: this.state.components.concat(<input type='text' value={this.state.task} name='task' onchange={this.change} key={this.state.count.length + 1} />)
        })
    }

Related Query

More Query from same tag