Skip to content

Commit

Permalink
[Fix] intersection observer 부분이 올라가서 삭제 #32
Browse files Browse the repository at this point in the history
why
작업중이던 내용이 올라감

how
삭제하고 올림
  • Loading branch information
WooYeonSeo committed Nov 25, 2019
1 parent af0dd8b commit 96c6e09
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions client/src/composition/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ const FeedContainer = () => {
}, [checkEnd]);

const target = useRef<HTMLElement>(null);
const onIntersect = ([entry], observer) => {
if (entry.isIntersecting) {
observer.unobserve(entry.target);
// await fetchItems();
observer.observe(entry.target);
}
};

useEffect(() => {
const observer = new IntersectionObserver(onIntersect, { threshold: 0.5 });
observer.observe(target);
return () => observer.disconnect();
}, []);

const fetchMoreFeed = async () => {
const { data: value } = await fetchMore({
Expand All @@ -66,12 +53,12 @@ const FeedContainer = () => {
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult) {
return prev;
} else {
const { feeds: feedItems } = fetchMoreResult;
const lastFeedItem = feedItems[feedItems.length - 1];
setCursor(lastFeedItem.createdAt);
}

const { feeds: feedItems } = fetchMoreResult;
const lastFeedItem = feedItems[feedItems.length - 1];
setCursor(lastFeedItem.createdAt);

return Object.assign({}, prev, {
feed: [...prev.feeds, ...fetchMoreResult.feeds]
});
Expand All @@ -92,9 +79,6 @@ const FeedContainer = () => {
<Feed content={feed.content} createdAt={feed.createdAt} />
))}
<span onClick={fetchMoreFeed}>click</span>
<div ref={target} className="Loading">
{isLoading && 'Loading...'}
</div>
</>
);
};
Expand Down

0 comments on commit 96c6e09

Please sign in to comment.