blacktokkies / toquiz-client

질문을 먹고 자라는 토끼들 ₍ᐢ.‸.⑅ᐢ₎ [Client]
https://toquiz.site/
MIT License
3 stars 1 forks source link

[질문 목록] 질문 목록에서 현재 시각 계속 업데이트하느라 전체 리스트가 다시 렌더링됨 #394

Closed leegwae closed 1 year ago

leegwae commented 1 year ago

현재 상황

export function TimeDiff({ target }: Props): JSX.Element {
  const now = useCurrentDate();
  return <div>{formatTimeDifference(now, target)}</div>;
}

<ul>
{questionList.map(question => <li><TimeDiff target={questioin.createdAt}></li>)}
<ul>

문제

해결

import React from 'react';

import { useCurrentDate } from '@/hooks/useCurrentDate';

import { formatTimeDifference } from './InfiniteQuestionList';

interface Props {
  start: Date;
  target: Date;
}
export function TimeDiff({ start, target }: Props): JSX.Element {
  const now = useCurrentDate({ start });
  return <div>{formatTimeDifference(now, target)}</div>;
}