Skip to content

Commit 2e99678

Browse files
committed
Add example
1 parent e1f1b36 commit 2e99678

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

packages/docs-gesture-handler/docs/components/wrapped-components.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ Components listed below come with a pre-applied `Native` gesture.
6060

6161
:::danger
6262
This callback may lead to infinite re-renders if not used carefully.
63+
64+
```tsx
65+
export default function App() {
66+
const [gesture, setGesture] = useState<NativeGesture | null>(null);
67+
68+
const updateGesture = (g: NativeGesture) => {
69+
// ❌ Wrong usage: calling setState here triggers a re-render,
70+
// which re-creates the ScrollView's Native gesture, which fires
71+
// this callback again → infinite re-render loop.
72+
setGesture(g);
73+
};
74+
75+
return (
76+
<GestureHandlerRootView style={{ flex: 1 }}>
77+
<ScrollView onGestureUpdate_CAN_CAUSE_INFINITE_RERENDER={updateGesture} />
78+
</GestureHandlerRootView>
79+
);
80+
}
81+
```
6382
:::
6483

6584
Those components also receive an additional prop named `onGestureUpdate_CAN_CAUSE_INFINITE_RERENDER`.

0 commit comments

Comments
 (0)