Skip to content

Instantly share code, notes, and snippets.

@dachinat
Created August 19, 2021 13:17
Show Gist options
  • Save dachinat/6580efa12cf254646c869d7d9f4ab458 to your computer and use it in GitHub Desktop.
Save dachinat/6580efa12cf254646c869d7d9f4ab458 to your computer and use it in GitHub Desktop.
import React, {useState, useEffect} from 'react';
export default () => {
const [input, setInput] = useState([]);
useEffect(() => {
addInput();
}, []);
const addInput = () => {
setInput([...input, renderInput()]);
};
const renderInput = () => {
return (
<div key={input.length + 1}>
<input type="text" />
<span><button onClick={addInput}>+</button></span>
</div>
);
}
console.log(input);
return (
<div>
{input}
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment