dont render 0

This commit is contained in:
Hailey
2024-09-02 01:11:09 -07:00
parent 006ee98226
commit 92445aeae5
+5 -6
View File
@@ -106,6 +106,8 @@ export function CountWheel({
const [key, setKey] = React.useState(0) const [key, setKey] = React.useState(0)
const [prevCount, setPrevCount] = React.useState(likeCount) const [prevCount, setPrevCount] = React.useState(likeCount)
const prevIsLiked = React.useRef(isLiked) const prevIsLiked = React.useRef(isLiked)
const formattedCount = formatCount(likeCount)
const formattedPrevCount = formatCount(prevCount)
React.useEffect(() => { React.useEffect(() => {
if (isLiked === prevIsLiked.current) { if (isLiked === prevIsLiked.current) {
@@ -118,9 +120,6 @@ export function CountWheel({
prevIsLiked.current = isLiked prevIsLiked.current = isLiked
}, [isLiked, likeCount]) }, [isLiked, likeCount])
const formattedCount = formatCount(likeCount)
const formattedPrevCount = formatCount(prevCount)
const enteringAnimation = const enteringAnimation =
shouldAnimate && shouldRoll shouldAnimate && shouldRoll
? isLiked ? isLiked
@@ -136,8 +135,8 @@ export function CountWheel({
return ( return (
<LayoutAnimationConfig skipEntering skipExiting> <LayoutAnimationConfig skipEntering skipExiting>
<View style={[a.justify_center]}>
{likeCount > 0 ? ( {likeCount > 0 ? (
<View style={[a.justify_center]}>
<Animated.View <Animated.View
entering={enteringAnimation} entering={enteringAnimation}
key={key} key={key}
@@ -154,10 +153,9 @@ export function CountWheel({
{formattedCount} {formattedCount}
</Text> </Text>
</Animated.View> </Animated.View>
) : null}
{/* Add 2 to the key so there are never duplicates */}
<Animated.View <Animated.View
entering={exitingAnimation} entering={exitingAnimation}
// Add 2 to the key so there are never duplicates
key={key + 2} key={key + 2}
style={[a.absolute]} style={[a.absolute]}
aria-disabled={true}> aria-disabled={true}>
@@ -173,6 +171,7 @@ export function CountWheel({
</Text> </Text>
</Animated.View> </Animated.View>
</View> </View>
) : null}
</LayoutAnimationConfig> </LayoutAnimationConfig>
) )
} }