๐Ÿค ์€์ง€log ๐Ÿค

[REACT] e.stopPropagation( ) ๋ณธ๋ฌธ

๐Ÿ’™ React

[REACT] e.stopPropagation( )

Eun_zii 2024. 1. 18. 15:06

์šฐ๋ฆฌ๊ฐ€ ๋งˆ์šฐ์Šค๋กœ ์–ด๋– ํ•œ ํƒœ๊ทธ(div, ul, li, a ๋“ฑ)๋ฅผ ํด๋ฆญํ–ˆ์„ ๊ฒฝ์šฐ ๋งŽ์€ ๋ถ„๋“ค์ด ํ•ด๋‹น ํƒœ๊ทธ๋งŒ ํด๋ฆญ์ด ๋˜์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. ํ•˜์ง€๋งŒ ํ•ด๋‹น ํƒœ๊ทธ๋งŒ์ด ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์ง€ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํƒœ๊ทธ๋ฅผ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ๋ถ€๋ชจ ํƒœ๊ทธ๋“ค๋„ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ์ธ์‹ํ•˜๊ณ  ๋ฐ˜์‘ํ•˜๊ฒŒ ๋œ๋‹ค. ์ด๊ฒƒ์„ ๋ฒ„๋ธ”์—…(Bubble Up) ๋˜๋Š” ๋ฒ„๋ธ”๋ง(Bubbling)์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

https://joshua1988.github.io/web-development/javascript/event-propagation-delegation/

 

 

์ด๋Ÿฌํ•œ ๋ฒ„๋ธ”๋ง ๋˜๋Š” ๋ฒ„๋ธ”์—…์„ ๋ง‰๋Š” ๊ฒƒ์ด stopPropagation์ด๋ผ๊ณ  ๋ณด๋ฉด ๋œ๋‹ค. ์ƒ์œ„์š”์†Œ๋กœ ํ•ด๋‹น ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•˜์ง€ ์•Š๊ณ  ์ž์‹ ๋งŒ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์ง€ํ•˜๋„๋ก ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด stopPropagation ์ด๋‹ค.

 

 

 

( Result ํด๋ฆญ โœ…) ์ด ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ๋‹จ์ง€ .last-el ๋งŒ ํด๋ฆญํ–ˆ์„ ๋ฟ์ธ๋ฐ ๋ถ€๋ชจ ์—˜๋ฆฌ๋จผํŠธ์—๊ฒŒ๋„ ์ด๋ฒคํŠธ๊ฐ€ ์ „ํŒŒ ๋จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์ด๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด e.stopPropagation ์ด๋‹ค. e.stopPropagation๋Š” ์ด๋ฒคํŠธ๊ฐ€ ์ƒ์œ„ ์—˜๋ฆฌ๋จผํŠธ์— ์ „๋‹ฌ๋˜์ง€ ์•Š๊ฒŒ ๋ง‰์•„ ์ค€๋‹ค.

 

 

๋‘๋ฒˆ์งธ ์ค„์— e.stopPropagation(); ๋ฅผ ์ถ”๊ฐ€์‹œํ‚จ๊ฒƒ ๋งŒ์œผ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ค‘๋‹จ ์‹œํ‚ฌ์ˆ˜ ์žˆ๋‹ค.

 

 

โค๏ธ ๋„์›€์ฃผ์‹ ๋ถ„ :

728x90