score:1

Accepted answer
  render() {
    return (
      <div className="App">
        {this.state.showForm && <form>
          {this.state.inputs.map((input, idx) => (
            <Employee key={idx}/>
          ))}
        </form>}
        <button onClick={this.handleAddInput}>Add New Employee</button>
        <button onClick={this.handleShowForm}>Show form</button>
      </div>
    );
  }

score:0

class Home extends React.Component {

state = { 
   employeesCount: 0,
   employees: []
}

render() {
    return (
        <div className='container-home'>
            <div className='min-margin'>
                {employees.map((eNumber) => {
                    return <Employee key={eNumber}/>
                }}
                <div className='container-append'>
                    <button onClick={() => this.setState({
                        employeesCount: employeesCount + 1,
                        employees: [...this.state.employess , (employeesCount + 1)]
                    })}>➕</button>
                </div>
            </div>
        </div>
    )
  }
}

score:0

import React from "react";

const Employee = (props) => {
  return(
    <div>Hello I am employee number {props.number}</div>
  )
}

class App extends React.Component {
  constructor() {
    super()
    this.state = { employees: [] }
  }


  addEmployee() {
    this.setState({
      employees: [...this.state.employees, <Employee number={this.state.employees.length} />]
    })
  }

  render() {
    return (
      <div>
        <div className='container-append'>
          <button onClick={() => this.addEmployee()}>➕</button>
        </div>
        { this.state.employees.map(employee => employee) }
      </div>
    )
  }
}
export default App;

Related Query

More Query from same tag