Skip to main content

scheduleOnUI

scheduleOnUI lets you schedule a function to be executed on the UI Runtime. The callback executes asynchronously and doesn't return a value.

Reference

import { scheduleOnUI } from 'react-native-worklets';

const myFunction = (): void => {
'worklet';
console.log('Hello from the UI Runtime!');
};

scheduleOnUI(myFunction); // Hello from the UI Runtime!

Type definitions

function scheduleOnUI<Args extends unknown[], ReturnValue>(
fun: (...args: Args) => ReturnValue,
...args: Args
): void

Arguments

fun

A reference to a function you want to schedule on the UI Runtime.

args

Arguments to pass to the function.

Remarks

  • The callback passed as the argument is automatically workletized and ready to be run on the UI Runtime.

  • Make sure not to execute scheduleOnUI on the UI Runtime or Worker Runtime as this will result in an error, unless you have the Bundle Mode enabled.

  • On the Web, scheduleOnUI schedules work to run on the next animation frame using requestAnimationFrame.