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} />)
})
}
Source: stackoverflow.com
Related Query
- How to dynamically add fields to a form on React
- How to add form fields dynamically in react js
- How do I add validation to the form in my React component?
- How to add "refs" dynamically with react hooks?
- React: dynamically add input fields to form
- How to get form data from input fields in React
- How to add components to list dynamically in React with no redundant render?
- How can i create input text fields dynamically in react js - JSX?
- How to add new props dynamically to the component using navigator in React Native
- How To Add More component dynamically React Native
- How to create dynamic form input fields in React with ANTd
- How to dynamically add css style to pseudo classes in React
- How do I add a React form data to a Firebase real-time database?
- How to add a tab dynamically when we click a button using React js and Bootsrap 4
- Add Form Fields Dynamically -- ReactJs
- How to dynamically show or hide form fields depending on the state of a BooleanInput field in react-admin?
- How to set a general onchange for the dynamic form fields coming from api in react js.?
- How to add animation in dynamically created react components
- How to submit react form fields on onChange rather than on submit using React-Hook-Form library
- How to handle a form with many fields in React
- Dynamically add errors when using useFieldArray with React Hook Form
- How to validate the form and send user to another page on successful data filled in form fields in React JS?
- How do I dynamically add styles to a React style attribute?
- How to add validation in Material ui form input fields
- React Redux - How do I build a form with material-ui that I can add inputs to?
- How to add child array input field dynamically in React JS
- How should I manage multiple select fields dynamically added in React JS?
- How can I add dynamic fields based on my selected attributes in react js?
- How to add a second button to the react form that not execute the first button handler function?
- Dynamic Forms - How to update the value of multiple form fields on 'onChange' event using react hooks?
More Query from same tag
- Why do I encounter: "TypeError: t(...).isPlaceholder is not a function" when "import './bootstrap/dist/css/bootstrap.min.css'"
- Getting error 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED'
- React JS: Two Filters on the same JSON data
- Next.js CompononentDidMount called before page loaded
- Can't Edit and Update properties with form Reactjs and MongoDB
- Setting state on array logs empty array multiple times
- How to cache a React app with service workers
- How to optimistically update item in a ListView
- Update internal state based on props (anti-pattern)
- React/Redux - Rest operator not working as expected
- i have the problem in i18next that the text not show from json data
- how to customize blueprintjs appearance in create-react-app
- Popup window disappearing after unclicking the button
- React: Passing down props to functional components
- Why show error [ react-router-dom@5.2.0 requires a peer of react@>=15 but none is installed. You must install peer dependencies yourself.]
- Babel loader unable to import React
- deploying create-react-app to heroku with express backend returns invalid host header in browser
- Axios throwing Internal server error but api url works
- Setting stockfish skill level (UCI / Javascript)
- Axios.delete(url[,config]): Type has no properties in common with type 'AxiosRequestConfig'
- @react-google-maps/api <GoogleMap> onClick not working
- Next.js - Pull data at specific times
- Using (Or ||) syntax inside of React useState for assignment
- React router Link changes URL, but doesn't render the component
- How to handle onChange value in date? reactjs
- Fetch console showing value but cant save it to a variable
- I am trying to use the react hook useContext() but its not working
- How to unit test an array as a prop using react-testing-library
- BrowserRouter - how to access history? Change location in component or in action?
- Make a webm blob into a file to upload to server