@geekapps/silo-elements-nextjs 0.2.59 → 0.2.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,6 +157,8 @@ function Video({
157
157
  () => ({ LOVE: parsed.rating?.counts?.LOVE ?? 0, LIKE: parsed.rating?.counts?.LIKE ?? 0, DISLIKE: parsed.rating?.counts?.DISLIKE ?? 0 })
158
158
  );
159
159
  const [userReaction, setUserReaction] = useState(parsed.rating?.userReaction ?? null);
160
+ const userReactionRef = useRef(userReaction);
161
+ userReactionRef.current = userReaction;
160
162
  const onReactRef = useRef(parsed.rating?.onReact);
161
163
  onReactRef.current = parsed.rating?.onReact;
162
164
  const [preview, setPreview] = useState(null);
@@ -1680,9 +1682,10 @@ function Video({
1680
1682
  setUserReaction(next);
1681
1683
  setRatingCounts((prev) => {
1682
1684
  const updated = { ...prev };
1685
+ const prev_reaction = userReactionRef.current;
1683
1686
  if (active) updated[key] = Math.max(0, (updated[key] ?? 0) - 1);
1684
1687
  else {
1685
- if (userReaction) updated[userReaction] = Math.max(0, (updated[userReaction] ?? 0) - 1);
1688
+ if (prev_reaction) updated[prev_reaction] = Math.max(0, (updated[prev_reaction] ?? 0) - 1);
1686
1689
  updated[key] = (updated[key] ?? 0) + 1;
1687
1690
  }
1688
1691
  return updated;