728x90
๐ React Event
- HTML DOM ์ด๋ฒคํธ์ ๋ง์ฐฌ๊ฐ์ง๋ก ์ฌ์ฉ์ ์ด๋ฒคํธ์ ๋ฐ๋ผ ์์ ์ ์ํํ ์ ์์.
- ๋ฆฌ์กํธ์๋ HTML๊ณผ ๋์ผํ ์ด๋ฒคํธ๊ฐ ์์
- ํด๋ฆญ, ๋๋ธํด๋ฆญ, ์ฒด์ธ์ง ๋ฑ๋ฑ.
๐ ํจ์๋ฅผ ๋ฃ์ผ๋ ค๋ฉด???
- ํจ์๋ฅผ ๋ฃ์ ๋๋ ์ค๊ดํธ {} ์ ๋ฃ์ด์ผํจ.
- <button onClick={sayHi}>์ธ์ฌ๋ฒํผ</button>
- ํ์ดํํจ์ ์ฒ๋ฆฌ :: <button onClick={ () => sayHi("ํ๊ธธ๋") }>์ธ์ฌ๋ฒํผ</button>
- ์ต๋ช ํจ์ ์ฒ๋ฆฌ :: <button onClick={ function(){sayHi("ํ๊ธธ๋")} }>์ธ์ฌ๋ฒํผ</button>
- ์ต๋ช
ํจ์์ ํ์ดํํจ์ ์๋ this ์ ์ฒ๋ฆฌ์ ๋ํด์ ๋ค๋ฅด๊ฒ ์๋ํ๊ธฐ ๋๋ฌธ์... ์ฃผ์ํด์ผํจ.
- ์ผ๋ฐ ํจ์ --> "๋๊ฐ ๋ถ๋ ๋์ง"
- ํ์ดํ ํจ์ --> "์ด๋์ ํ์ด๋ฌ๋์ง"
import { createRoot } from 'react-dom/client';
function App() {
const sayHi = (name, e) => { // const sayHi = function (name){~} // ์ฌ๊ธฐ์๋ ๋๋ค ๋์ผ.
alert(`${name}๋ ์๋
ํ์ธ์, \n e.type์ -- ${e.type}`);
console.log(e.type);
}
return (
// <button onClick={ function(){ sayHi("ํ๊ธธ๋") }}>์ธ์ฌ๋ฒํผ</button> // ์ต๋ช
ํจ์
// <button onClick={ () => { sayHi("ํ๊ธธ๋") }}>์ธ์ฌ๋ฒํผ</button> // ํ์ดํํจ์ // ๋ฆฌ์กํธ์์๋ ํ์ดํํจ์๋ฅผ ์ฃผ๋ก ์จ์ผํจ.
// ์ธ์ ์ ๋ฌํ ๋๋ ๋ฌด์กฐ๊ฑด ํ์ดํ ํจ์ ์จ์ผํจ.
// <button onClick={ sayHi("ํ๊ธธ๋") }>์ธ์ฌ๋ฒํผ</button> // ํด๋ฆญํ์ง ์์๋ ๋ฐ๋ก alert ์ฐฝ ๋ธ.
<button onDoubleClick={ (event) => { sayHi("ํ๊ธธ๋", event) }}>์ธ์ฌ๋ฒํผ</button> // sayHi ํจ์๋ฅผ ํธ๋ฆฌ๊ฑฐํ.(๋ฐ์์ํจ) ์ด๋ฒคํธ์ ์ ๊ทผํ ์ ์๋ ๊ฒ์. event
)
}
createRoot(document.getElementById('reactEvent')).render(
<App />
);
์ถ์ฒ :
[์์ด๋ณด ํํ์ด์ง๋ง๋ค๊ธฐ ๋ฆฌ์กํธ ๊ธฐ์ด ๊ฐ์]
https://www.youtube.com/watch?v=kgo-ZUdd004&list=PLTb3qGCzYjS2AliTIbz9eAGjZSdEQa3m1&index=19
๊ฐ๋ฐ ๊ณต๋ถ๋ฅผ ์ํ ๋ธ๋ก๊ทธ ์ ๋๋ค.
์ค๋ฅ๊ฐ ์๋ค๋ฉด ๋๊ธ๋ก ์๋ ค์ฃผ์ธ์!
๊ฐ์ฌํฉ๋๋ค.

728x90
'front > react' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [react] css ์ฌ์ฉ ๊ด๋ จ (inline css, css obj, import css, import css module, composes, global css className) (1) | 2026.01.02 |
|---|---|
| [react] createPortal, Suspense (0) | 2026.01.01 |
| [react] ์ปดํฌ๋ํธ, Props ์ ๋ํด์... (0) | 2025.12.28 |
| [react] JSX ๋? (ํํ์, ์์ฑ, if๋ฌธ์ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง) (0) | 2025.12.28 |
| [ES6] ๊ธฐ์ด ์ ๋ฆฌ (0) | 2025.12.27 |