Skip to content
New issue

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

JavaScript로 제어하는 스크롤 스냅 구현 #459

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions client/src/components/CafeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useRef, useState } from 'react';
import { styled } from 'styled-components';
import useIntersection from '../hooks/useIntersection';
import type { Cafe } from '../types';
import Image from '../utils/Image';
import CafeActionBar from './CafeActionBar';
Expand All @@ -9,23 +8,15 @@ import CafeSummary from './CafeSummary';

type CardProps = {
cafe: Cafe;
onIntersect?: (intersection: IntersectionObserverEntry) => void;
};

const CafeCard = (props: CardProps) => {
const { cafe, onIntersect } = props;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 Intersection도 필요가 없나보네

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럼요~~ DOM의 제어로 인해 발생하는 이벤트를 구독할 필요가 없습니다

const { cafe } = props;

const [isShowDetail, setIsShowDetail] = useState(false);
const [currentImageIndex, setCurrentImageIndex] = useState(0);

const ref = useRef<HTMLDivElement>(null);
const intersection = useIntersection(ref, { threshold: 0.7 });

useEffect(() => {
if (intersection) {
onIntersect?.(intersection);
}
}, [intersection?.isIntersecting]);

useEffect(() => {
const handleScroll = () => {
Expand Down
Loading
Loading