Skip to content

Commit fbfb9fc

Browse files
committed
Update autoworkletization
1 parent cc3f815 commit fbfb9fc

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

packages/docs-gesture-handler/docs/fundamentals/callbacks-events.mdx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,38 @@ export enum PointerType {
180180

181181
## Automatic [**workletization**](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary/#to-workletize) of gesture callbacks
182182

183-
[Worklets' Babel plugin](https://docs.swmansion.com/react-native-worklets/docs/worklets-babel-plugin/about) is setup in a way that automatically marks callbacks passed to gestures in the configuration chain as worklets. This means that you don't need to add a `'worklet';` directive at the beginning of the functions.
183+
[Worklets' Babel plugin](https://docs.swmansion.com/react-native-worklets/docs/worklets-babel-plugin/about) is setup in a way that automatically marks callbacks passed to gestures in the configuration chain as worklets. This means that you don't need to add a `'worklet';` directive at the beginning of the functions. Here is an example that will be automatically workletized:
184+
185+
```jsx
186+
const gesture = useTapGesture({
187+
onBegin: () => {
188+
console.log(_WORKLET);
189+
},
190+
})
191+
```
192+
193+
And here is one that won't:
194+
195+
```jsx
196+
const callback = () => {
197+
console.log(_WORKLET);
198+
};
199+
200+
const gesture = useTapGesture({
201+
onBegin: callback,
202+
})
203+
```
204+
205+
In the above case, you should add a [`"worklet";`](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary/#worklet) directive at the beginning of the callbacks, like so:
206+
207+
```jsx
208+
const callback = () => {
209+
// highlight-next-line
210+
"worklet";
211+
console.log(_WORKLET);
212+
};
213+
214+
const gesture = useTapGesture({
215+
onBegin: callback,
216+
})
217+
```

0 commit comments

Comments
 (0)