runOnUISync
runOnUISync
lets you run a workletized function synchronously on the UI Runtime.
Reference
import { runOnUISync } from 'react-native-worklets';
const myFunction = (num: number): number => {
'worklet';
return num + 1;
};
const result: number = runOnUISync(myFunction, 0);
console.log(result); // 1


Type definitions
function runOnUISync<Args extends unknown[], ReturnValue>(
worklet: (...args: Args) => ReturnValue,
...args: Args
): ReturnValue
Arguments
worklet
A function you want to execute on the UI Runtime.
args
Arguments to pass to the function.
Returns
runOnUISync
returns the return value of the function passed as the first argument. It can only return values that can be converted to a Serializable.
Remarks
-
The callback passed as the argument is automatically workletized and ready to be run on the UI Runtime.
-
Make sure not to execute
runOnUISync
on the UI Runtime or Worker Runtime as this will result in an error.