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 |
Tags
- MIPS
- Algorithm
- while
- php
- python
- Pipelining
- MacOS
- mysql
- data structure
- javascript
- Linux
- CSS
- function
- Class
- control
- github
- for
- system
- DB
- DoM
- react
- Java
- DS
- instruction
- architecture
- XML
- html
- web
- DATAPATH
- computer
Archives
- Today
- Total
YYYEJI
[React] 버튼 onClick 속성에 두 개의 기능 넣기 본문
728x90
우선 onClick에 넣을 두 개의 함수를 선언합니다.
const [counter, setCounter] = React.useState(1);
const [sum, setSum] = React.useState(0);
const onCount = () => {
setCounter((current) => current+1);
}
const onSum = () => {
setSum((current) => current+1);
}
<button> tag 안에 onClick 속성을 아래와 같이 넣어주면
<button className="button" onClick={()=>{onCount(); onSum();}}>Button</button><br/>
두 개의 기능을 하는 버튼을 생성할 수 있습니다.
◡̈
'Web Application Server (WAS)' 카테고리의 다른 글
[React] react-dom.development.js:86 Warning: validateDOMNesting(...): <h2> cannot appear as a descendant of <p> 에러 (0) | 2023.01.16 |
---|---|
[React] 리액트(React)에서 텍스트 줄바꿈하기 (0) | 2023.01.14 |
[React] Link 컴포넌트 밑줄 제거하기 (0) | 2023.01.14 |
[React] 함수형 컴포넌트에 props 전달하기 (0) | 2023.01.13 |
[JSP] Cannot resolve taglib with uri http://java.sun.com/jsp/jstl/core 에러 (0) | 2023.01.11 |