@bitdrift/react-native
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

bd-react-native

bitdrift integration for React Native

Installation

npm install @bitdrift/react-native

Usage

Expo

If you are using Expo to build your React Native app and don't want to use an ejected workflow, you can use the @bitdrift/react-native package to initialize the Capture library and log messages at different log levels. Note that this initializes the library later than is ideal, but should still provide most of the benefits of using Capture.

import { init, trace, debug, info, warn, error } from '@bitdrift/react-native';
init('<api key>');

info('Hello, World!');

For all Expo usages, make sure to add @bitdrift/react-native to the plugins field in your app.json file. This helps ensure setting up the native modules correctly.

{
  "expo": {
    "plugins": [
      "@bitdrift/react-native"
    ]
  }
}

Expo Go

Due to loading native modules, the @bitdrift/react-native package is not supported in Expo Go.

React Native / Ejected Expo

First initialize the Capture library by using the per-platform instructions found here.

For iOS, perform the initialization in didFinishLaunchingWithOptions in your AppDelegate.m file.

-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  [CAPLogger configureWithAPIKey:@"<api key>" sessionStrategy: CAPSessionStrategy.fixed]];

  ...

For Android, perform the initialization in onCreate in your MainApplication.kt file.

  override fun onCreate() {
    super.onCreate()
    Capture.Logger.configure(
      apiKey = "<api key>",
      sessionStrategy = SessionStrategy.Fixed()
    )
    ...
  }

To add custom log messages from your React Native app, import the log level functions from the @bitdrift/react-native package and use them to log messages at the desired log level.

import { trace, debug, info, warn, error } from '@bitdrift/react-native';

// Log at the desired log level using the different log level functions.

trace('Hello, World!');

debug('Hello, World!');

info('Hello, World!');

warn('Hello, World!');

error('Hello, World!');

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Readme

Keywords

none

Package Sidebar

Install

npm i @bitdrift/react-native

Weekly Downloads

0

Version

0.3.1

License

SEE LICENSE IN LICENSE

Unpacked Size

701 kB

Total Files

182

Last publish

Collaborators

  • jacksonbd
  • snowbd