Created
August 19, 2021 13:17
-
-
Save dachinat/6580efa12cf254646c869d7d9f4ab458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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