Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to append more elements after click in react

const App = () => {
  const [count, setCount] = useState(0);

  return <Fragment>
    <button onClick={() => setCount(count + 1)}>Click me</button>
    { [...Array(count)].map((_, i) => <AddedElement key={i} />) }
  </Fragment>
}
 
PREVIOUS NEXT
Tagged: #append #elements #click #react
ADD COMMENT
Topic
Name
6+2 =