Skip to content

Commit

Permalink
fix: reading shared value during render
Browse files Browse the repository at this point in the history
Fix #20
  • Loading branch information
omahili committed Jan 15, 2025
1 parent 0f0f3e4 commit ac43fad
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/components/ReorderableListCore/useReorderableListCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useMemo} from 'react';
import React, {useCallback, useEffect, useMemo} from 'react';
import {
FlatList,
LayoutChangeEvent,
Expand Down Expand Up @@ -98,12 +98,12 @@ export const useReorderableListCore = <T>({
const dragEndHandlers = useSharedValue<
((from: number, to: number) => void)[][]
>([]);

// animation duration as a shared value allows to avoid re-rendering of all cells on value change
const startY = useSharedValue(0);
const duration = useSharedValue(animationDuration);
if (duration.value !== animationDuration) {

useEffect(() => {
duration.value = animationDuration;
}
}, [duration, animationDuration]);

const listContextValue = useMemo(
() => ({
Expand All @@ -115,8 +115,6 @@ export const useReorderableListCore = <T>({
[draggedHeight, currentIndex, draggedIndex, dragEndHandlers],
);

const startY = useSharedValue(0);

const panGestureHandler = useMemo(
() =>
Gesture.Pan()
Expand Down

0 comments on commit ac43fad

Please sign in to comment.