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
Colours connect each executing thread to its current code line. Recently executed lines fade over the next three ticks.
Console 0
No output yet


Type definitions
type WorkletClosure = unknown[];
export type WorkletStackDetails = [
error: Error,
lineOffset: number,
columnOffset: number,
];
interface WorkletInitData {
/** Only when bytecode isn't toggled. */
code?: string;
/** Only in production builds and explicitly toggled. */
bytecode?: ArrayBuffer;
/** Only in dev builds. */
location?: string;
/** Only in dev builds. */
sourceMap?: string;
}
interface WorkletProps {
__closure?: WorkletClosure;
__workletHash: number;
/** Only in Legacy Eval Mode. */
__initData?: WorkletInitData;
/** `__stackDetails` is removed after parsing. */
__stackDetails?: WorkletStackDetails;
/** 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
-
In Legacy Eval Mode, call it on the RN Runtime. On a Worklet Runtime, it returns
falseeven for worklet functions. In Bundle Mode, it works on every runtime. -
Call it only after the worklet function is declared. Before the declaration, it never returns
true.isWorkletFunction(myWorklet); // Never returns true.
function myWorklet() {
'worklet';
}