๐Ÿ“šย Reference


๐Ÿ“œย Chapter


useInfiniteQuery

โ€ฃ

react-intersection-observer


์‚ฌ์šฉํ•˜๋Š” ์ด์œ 


๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฒ• (Hook ๋ฐฉ์‹)


import { useInView } from 'react-intersection-observer';

const MyComponent = () => {
  // ref: ๊ฐ์‹œํ•  ์š”์†Œ๋ฅผ ์ง€์ •
  // inView: ์š”์†Œ๊ฐ€ ํ™”๋ฉด์— ๋ณด์ด๋ฉด true, ์•„๋‹ˆ๋ฉด false
  const { ref, inView } = useInView({
    threshold: 0, // ์š”์†Œ๊ฐ€ 1ํ”ฝ์…€์ด๋ผ๋„ ๋ณด์ด๋ฉด ๊ฐ์ง€ (0 ~ 1 ์‚ฌ์ด ๊ฐ’)
    triggerOnce: false, // ๋”ฑ ํ•œ ๋ฒˆ๋งŒ ๊ฐ์ง€ํ• ์ง€ ์—ฌ๋ถ€
  });

  return (
    <div ref={ref} style={{ height: '100px', background: 'lightblue' }}>
      {inView ? '๋ณด์—ฌ์š”! ๐Ÿ‘€' : '์•ˆ ๋ณด์—ฌ์š”... ๐Ÿ™ˆ'}
    </div>
  );
};