Skip to main content

Method arguments

Boolean argument

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

// ...

export interface Spec extends TurboModule {
myMethod(enabled: boolean, checked?: boolean): void
}

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

Number argument

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

// ...

export interface Spec extends TurboModule {
myMethod(count: number, optionalCount?: number): void
}

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

String argument

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

// ...

export interface Spec extends TurboModule {
myMethod(name: string, label?: number): void
}

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

Array argument

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

// ...

export interface Spec extends TurboModule {
myMethod(data: number[], optionalData?: string[]): void
}

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

Object argument

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

// ...

export interface Spec extends TurboModule {
myMethod(config: { flag: boolean, option: string }, optionalConfig?: { count: number }): void
}

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