HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🐣
프론트엔드 데브코스 4기 교육생
/
🐶
이재호2팀
/
🌰
리액트 스터디
/
🌳
10월12일 목요일 1차스터디(Adding Interactivity - 상호작용 추가하기)
/
이벤트에 응답하기

이벤트에 응답하기

  • 이벤트 핸들러 props는 보통 on prefix로 시작한다.
    • ex) onContentUpdate
  • 이벤트 전파(propagate, bubbling): 이벤트가 발생한 곳에서 시작하여 트리 위로 올라가는 것
    • onScroll제외, 모든 이벤트는 React에서 전파된다.
    • 이벤트 전파를 막으려면 e.stopPropagation()
    • 기본 동작을 막으려면 e.preventDefault()
  • 이벤트 이름 끝에 Capture suffix를 추가하면 전파 로직과 관련된 이벤트들이 기록된다.
    • ex) onBlurCapture, onFocusCapture, onMouseDownCapture, ...
  • 이벤트 핸들러는 사이드 이펙트가 가장 많이 발생하는 곳이다. = 이벤트 핸들러는 순수할 필요가 없다.
https://react-ko.dev/learn/responding-to-events