S
S
Sanchik972018-12-22 13:09:30
React
Sanchik97, 2018-12-22 13:09:30

How to render another component multiple times on button click?

Good afternoon! Let's say there is a button that, when clicked, will add an Input component to the page! If you write like this:

import React from 'react'
import { Input } from 'InputComponent'

export default class Parent extends React.Component {
  state = {
    InputCallState: false
  }

  inputStateHandler = () => {
    this.setState({
      inputCallState: true
    })
  }
  render() {
    return (
      <div>
        <button onClick={this.inputStateHandler}>Добавить компонент</button>
        {this.state.inputCallState ? <Input /> : null}
      </div>
    )
  }
}

The component will be called once. How can I add a new Input component every time the button is clicked?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-12-22
@Sanchik97

Able to store an array of entities, render inputs in a loop during rendering, add data to the array when a button is pressed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question