We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// μ€ν¬λ‘€ μ΄λ²€νΈμ ν΄λ¦ μ΄λ²€νΈ μ€νμ λ§νμ μ¬λΌμ§λλ‘ useEffect(() => { window.addEventListener('scroll', handleScroll); window.addEventListener('click', handleScroll); return () => { window.removeEventListener('scroll', handleScroll); window.removeEventListener('click', handleScroll); }; }, []); // μ€ν¬λ‘€, ν΄λ¦ μ΄λ²€νΈ const handleScroll = (e) => { // μ€ν¬λ‘€ μ, μ무곳 ν΄λ¦μ simpleTip λ§νμ μ¬λΌμ§κ² if (window.scrollY >= 100 || onModal && (!el.current || !el.current?.contains(e.target))){ setOnModal(false) } };
useEffectλ₯Ό μ¬μ©ν΄μ μ€ν¬λ‘€ μ΄λ²€νΈλ click μ΄λ²€νΈκ° μΌμ΄λ λ handleScroll μ΄λΌλ ν¨μκ° λμλλλ‘ νλ€. κ·Έλμ useEffect κΈ°λ₯λ΄μ μλ retrun κ°μ ν΅ν΄ cleanup μμ κΉμ§ νλ€. (removeEventListener == μ΄λ²€νΈλ₯Ό μ§μμ£Όλ)
handleScroll
removeEventListener
κ·Έλ¦¬κ³ μλΉμ€ ν΄ν λ§νμ μ΄ μ¬λΌμ§λ 쑰건μ 2κ°μ§λ€
κ·Όλ° μμ νλ©΄μ λ¬Έμ μ μ΄ λ¬΄μμ΄λλ©΄, λ©μΈνμ΄μ§μ 첫 λ²μ§Έλ‘ λνλλ λͺ¨λ¬μ ν΄λ¦νμ¬ λ«κ² λ κ²½μ°, μ΄λ²€νΈ λ²λΈλ§μ΄ μΌμ΄λμ λ§νμ κΉμ§ λμμ μ¬λΌμ§λ€. κ·Έλμ 첫 λ²μ§Έλ‘ λνλλ λͺ¨λ¬μ λ«μ λμ close λλ μ΄λ²€νΈ μͺ½μλ€κ° μ΄λ²€νΈ λ²λΈλ§μ μλ λ©μλλ₯Ό μ¬μ©ν΄μ λ§μμ£Όμλ€.
close
event.stopPropagation() μ μ¬μ©ν΄μ£Όλ©΄ λλ€.
event.stopPropagation()
μ΄λ²€νΈκ° μ°μνμ¬ λ°μνλ λ²λΈ νμμ μλ―Ένλ€. μμ μ리먼νΈμμ μ΄λ²€νΈ λ°μ μ, λΆλͺ¨ μ리먼νΈμ κ°μ μ΄λ²€νΈκ° μ€μ λμ΄ μλ€λ©΄ ν΄λΉ μ΄λ²€νΈμ ν λΉλ κΈ°λ₯λ ν¨κ» μ€νλλ€. κ·Έλμ μ΄ κ°μ νμμ λ§κΈ° μν΄μλ e.stopPropagation() μ μ¬μ©ν΄μ λ§μμ£Όλ©΄ λλ€.
e.stopPropagation()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
react λ©μΈ νμ΄μ§μμ SIMPLE μλΉμ€ ν΄ν λ§νμ λμ°λ©΄μ λ°°μ΄μ μ 리
useEffectλ₯Ό μ¬μ©ν΄μ μ€ν¬λ‘€ μ΄λ²€νΈλ click μ΄λ²€νΈκ° μΌμ΄λ λ
handleScroll
μ΄λΌλ ν¨μκ° λμλλλ‘ νλ€.κ·Έλμ useEffect κΈ°λ₯λ΄μ μλ retrun κ°μ ν΅ν΄ cleanup μμ κΉμ§ νλ€. (
removeEventListener
== μ΄λ²€νΈλ₯Ό μ§μμ£Όλ)κ·Έλ¦¬κ³ μλΉμ€ ν΄ν λ§νμ μ΄ μ¬λΌμ§λ 쑰건μ 2κ°μ§λ€
κ·Όλ° μμ νλ©΄μ λ¬Έμ μ μ΄ λ¬΄μμ΄λλ©΄,
λ©μΈνμ΄μ§μ 첫 λ²μ§Έλ‘ λνλλ λͺ¨λ¬μ ν΄λ¦νμ¬ λ«κ² λ κ²½μ°, μ΄λ²€νΈ λ²λΈλ§μ΄ μΌμ΄λμ λ§νμ κΉμ§ λμμ μ¬λΌμ§λ€.
κ·Έλμ 첫 λ²μ§Έλ‘ λνλλ λͺ¨λ¬μ λ«μ λμ
close
λλ μ΄λ²€νΈ μͺ½μλ€κ° μ΄λ²€νΈ λ²λΈλ§μ μλ λ©μλλ₯Ό μ¬μ©ν΄μ λ§μμ£Όμλ€.event.stopPropagation()
μ μ¬μ©ν΄μ£Όλ©΄ λλ€.
π₯ μ΄λ²€νΈ λ²λΈλ§μ΄λ ?
μ΄λ²€νΈκ° μ°μνμ¬ λ°μνλ λ²λΈ νμμ μλ―Ένλ€.
μμ μ리먼νΈμμ μ΄λ²€νΈ λ°μ μ, λΆλͺ¨ μ리먼νΈμ κ°μ μ΄λ²€νΈκ° μ€μ λμ΄ μλ€λ©΄ ν΄λΉ μ΄λ²€νΈμ ν λΉλ κΈ°λ₯λ ν¨κ» μ€νλλ€.
κ·Έλμ μ΄ κ°μ νμμ λ§κΈ° μν΄μλ
e.stopPropagation()
μ μ¬μ©ν΄μ λ§μμ£Όλ©΄ λλ€.The text was updated successfully, but these errors were encountered: