executeOnUIRuntimeSync
executeOnUIRuntimeSync
lets you run a workletized function synchronously on the UI thread.
Reference
import { executeOnUIRuntimeSync } from 'react-native-worklets';
// RN Runtime, JS thread
const result: number = executeOnUIRuntimeSync((): number => {
return 1;
})();
console.log(result); // 1


Type definitions
function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(
worklet: (...args: Args) => ReturnValue
): (...args: Args) => ReturnValue;
Arguments
worklet
A reference to a function you want to execute on the UI Runtime on the current thread. Arguments to your function have to be passed to the function returned from executeOnUIRuntimeSync
i.e. executeOnUIRuntimeSync(setValue)(10);
.
Returns
executeOnUIRuntimeSync
returns the return value of the worklet.
Don't forget to call the function returned from executeOnUIRuntimeSync
.
Remarks
-
It's a common mistake to execute function inside of
executeOnUIRuntimeSync
like this:. Here, the correct usage would beexecuteOnUIRuntimeSync(myWorklet(10))()
executeOnUIRuntimeSync(myWorklet)(10)
. -
The callback passed as the argument is automatically workletized and ready to be run on the UI thread.
-
Make sure not to execute
executeOnUIRuntimeSync
on the UI thread as this will result in an error.
Platform compatibility
Android | iOS | Web |
---|---|---|
✅ | ✅ | ✅ |