React

[React] React 이벤트

FRDYtheme 2022. 12. 30. 14:52

React 이벤트

on-접두어 + 첫글자 대문자 이벤트명으로 작성

<button onClick={함수}>클릭</button>
function Ex3_event(props) {
  const handleClick1 = () => {
    console.log("handleClick1");
  };
  const handleClick2 = () => {
    console.log("handleClick2")
  }
  const num = (param) => {
    console.log(param + param)
  }
  return (
    <div>
      <h1>event</h1>
      <h2>'on-접두어 + 첫글자 대문자 이벤트명</h2>
      <p>
        {/* js: onclick / react: onClick*/}
        <button onClick={handleClick1}>클릭</button>
        <button onClick={handleClick2}>클릭</button>
      </p>
      <p>
        <button onClick={()=> console.log("직접작성")}>버튼</button>
      </p>
      <p>
        <button onClick={() => num(100)}>숫자 출력</button>
      </p>
    </div>
  );
}
export default Ex3_event;

'React' 카테고리의 다른 글

[React] react 이미지 경로  (0) 2023.01.03
[React] state 상태  (0) 2022.12.30
[React] React에서의 map 특징  (0) 2022.12.30
[React] React 기초  (0) 2022.12.29
[React] JSX 규칙  (0) 2022.12.29