isWorkletFunction
Available from 0.1.0
isWorkletFunction checks if a function is a worklet function. It only works with Worklets Babel 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
Console 0
No output yet
Output appears here as the code runs.


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
-
Do not call it before the worklet function is declared, as it will always return
falsethen.isWorkletFunction(myWorklet); // Will always return false.
function myWorklet() {
'worklet';
}