Skip to content

Commit

Permalink
[#22] feat : re-render시에 변하지 않는 Guard를 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
choibumsu committed Feb 21, 2021
1 parent 09dafbb commit a485f4f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/MainSection/Timer/DisplayTime/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const animationConfig = {
delay: 500,
}

const guardConfig = {
disappearTime: 100,
appearTime: 800,
}

const getAnimationObj = (
scale: number,
translateY: string,
Expand All @@ -56,6 +61,8 @@ export const DisplayTime: React.FC<DisplayTimeProps> = ({
]
const [inAnimation, setInAnimation] = useState<AnimationType>()
const [outAnimation, setOutAnimation] = useState<AnimationType>()
const [guardAnimation, setGuardAnimation] = useState<AnimationType>()
const [guard, setGuard] = useState<string>(nextValue)

useEffect(() => {
setInAnimation(
Expand All @@ -67,6 +74,9 @@ export const DisplayTime: React.FC<DisplayTimeProps> = ({
)
)
setOutAnimation(getAnimationObj(1, '0', 'initial', 1))
setTimeout(() => {
setGuard(nextValue)
}, guardConfig.disappearTime)

setTimeout(() => {
setInAnimation(
Expand All @@ -81,6 +91,10 @@ export const DisplayTime: React.FC<DisplayTimeProps> = ({
)
)
}, animationConfig.delay)

setTimeout(() => {
setGuardAnimation(getAnimationObj(1))
}, guardConfig.appearTime)
}, [nextTime])

const getLetterElements = (
Expand Down Expand Up @@ -108,6 +122,9 @@ export const DisplayTime: React.FC<DisplayTimeProps> = ({
{getLetterElements(currentImmutable)}
{getLetterElements(currentMutable, outAnimation)}
</div>
<div className="next-value guard">
{getLetterElements(guard, guardAnimation)}
</div>
</div>
<div className="unit">{unit}</div>
</div>
Expand Down

0 comments on commit a485f4f

Please sign in to comment.