rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar
https://docs.rollbar.com/docs/javascript
MIT License
566 stars 212 forks source link

React + React Native compatibility #1109

Closed waltjones closed 1 year ago

waltjones commented 1 year ago

Description of the change

Enables code compatibility between Rollbar-react, Rollbar.js and Rollbar-react-native, including Typescript compatibility.

Allows the same initialization, whether the target is web/JS only or JS + Native.

const rollbarReactNative = new Client({/* config */})
const rollbar = rollbarReactNative.rollbar

export default function App() {
  return (
    <Provider instance={rollbar} />
  )
}

How this works When rollbar-react-native detects it is on a web-only target, it returns a browser-js instance. When it is on a web + native target, it returns a rollbar-react-native instance with a browser-js instance at the rollbar property.

This PR allows the app code to access the browser-js instance at the rollbar property regardless of which instance type is returned.

Type of change

Related issues

Fixes https://app.shortcut.com/rollbar/story/121632

Development