반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Tags
- bit
- leetcode
- component
- count
- routes
- state
- node.js
- array
- nodeJS
- Callback
- treenode
- route
- axios
- c++
- Navigation
- 비트연산
- JSX
- css
- BinaryTree
- MySQL
- event
- Props
- DP
- queue
- UE5
- map
- Context
- server
- priority_queue
- React
Archives
- Today
- Total
목록setArray (1)
우사미 코딩
[React] state - 배열 초기화, 새로운 요소 추가하기
import { useState } from "react"; function getRandomAnimal(){ const animals = ['bird','cat','cow','dog','gator', 'horse']; return animals[Math.floor(Math.random() * animals.length)]; } function App(){ const[animals, setAnimals] = useState([]); const handleClick = () =>{ setAnimals([...animals, getRandomAnimal()]); console.log(animals); } return ( Add animal {animals} ); } export default App; lin..
React
2023. 6. 23. 14:24