Skip to main content
Version: 1.0 (beta)

isWorkletFunction

isWorkletFunction checks if a function is a worklet function. It only works with the Worklet Syntax plugin enabled. Unless you are doing something with internals of the Worklets library you shouldn't need to use this function.

Reference​

Both checks run on the RN Runtime. Checking a function doesn't execute it or schedule it on another thread.

Code

Code

Colours connect each executing thread to its current code line. Recently executed lines fade over the next three ticks.

function workletFunction() {
'worklet';
return 1;
}
function nonWorkletFunction() {
return 1;
}
const isWorklet = isWorkletFunction(workletFunction);
console.log(isWorklet); // true
const isNonWorklet = isWorkletFunction(nonWorkletFunction);
console.log(isNonWorklet); // false

Type definitions

type WorkletClosure = unknown[];

interface WorkletProps {
__closure?: WorkletClosure;
__workletHash: number;
/** Only in dev builds. */
__pluginVersion?: string;
}

type WorkletFunction<
TArgs extends unknown[] = unknown[],
TReturn = unknown,
> = ((...args: TArgs) => TReturn) & WorkletProps;

function isWorkletFunction<
Args extends unknown[] = unknown[],
ReturnValue = unknown,
>(value: unknown): value is WorkletFunction<Args, ReturnValue>;

Arguments​

value​

A function to check if it is a worklet function.

Returns​

isWorkletFunction returns a boolean value.

Remarks​

  • Call it on the RN Runtime. On a Worklet Runtime, it returns false even for worklet functions.

  • Call it only after the worklet function is declared. Before the declaration, it never returns true.

    isWorkletFunction(myWorklet); // Never returns true.

    function myWorklet() {
    'worklet';
    }