[react] scroll event

dev stefanCho·2021년 5월 14일
0

react

목록 보기
1/19
post-custom-banner

Vanilla js에서는 window.addEventListener('scroll', callback) 형태로 사용한다.

onScroll

React js에서 특정 component에 onScroll 을 붙여서 사용할 수 있다.

예를 들면) Ant Design의 Modal Component를 사용하는데, 거기에 overflow: scroll이 있다면 해당 element (예를 들면 div)에 onScroll을 붙인다.

const MyComponent = () => {
    return (
        <Modal>
            <div className="list-container" onScroll={() => console.log('scrolled')}>
            What is Lorem Ipsum?
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's 
            standard dummy text ever since the 1500s, 
            when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
            It has survived not only five centuries, 
            but also the leap into electronic typesetting, remaining essentially unchanged. 
            It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 
            and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            </div>
        </Modal>
    )
}
profile
Front-end Developer
post-custom-banner

0개의 댓글