Skip to main content

Method types

Void method

Void methods can take multiple arguments and do not return any value.

src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

// ...

export interface Spec extends TurboModule {
myAwesomeVoidMethod(): void
myAwesomeVoidMethodWithArguments(numArg: number, objArg: { firstObjProp: string, secondObjProp?: boolean }): void
}

export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');

Sync method

Sync methods can take multiple arguments and synchronously return the value.

src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

// ...

export interface Spec extends TurboModule {
myAwesomeSyncMethod(): number
myAwesomeSyncMethodWithArguments(numArg: number, objArg: { firstObjProp: string, secondObjProp?: boolean }): number
}

export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');

Promise method

Promise methods can take multiple arguments and asynchronously return the value.

src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

// ...

export interface Spec extends TurboModule {
myAwesomePromiseMethod(): Promise<boolean>
myAwesomePromiseMethodWithArguments(numArg: number, objArg: { firstObjProp: string, secondObjProp?: boolean }): Promise<boolean>
}

export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');

Callback method

Callback methods can take multiple arguments including callback arguments which are used to communicate from native to JS world. Callbacks should be put as last arguments in the method.

src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

// ...

export interface Spec extends TurboModule {
myAwesomeCallbackMethod(myResultCallback: () => void): void
myAwesomeCallbackMethodWithArguments(numArg: number, objArg: { firstObjProp: string, secondObjProp?: boolean }, myResultCallback: () => void): void
}

export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');