> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Basic usage

> Example commands for the median-js-bridge npm package.

## npm library usage

> [!TIP]
>
> **Use `Median`, not `median`, with the npm package**
>
> When importing the Median JavaScript Bridge via the npm package, always use the capitalized `Median` object to access methods. The lowercase `median` is reserved for the injected JavaScript Bridge in native environments.
>
> To avoid semantic errors and enable intelligent code completion, ensure your IDE is configured to support type hinting for the `Median` object.

### Example: Importing and using Median in React

Median JavaScript Bridge

```javascript JavaScript theme={null}
import Median from "median-js-bridge";
import React, { useEffect } from "react";

const App: React.FC = () => {
useEffect(() => {
Median.onReady(() => {
console.log("Median app ready!");
});
}, []);
}

```

## Example commands

The following methods are available when using the `median-js-bridge` npm package:

### Check if running in a native app

Median JavaScript Bridge

```javascript JavaScript theme={null}
Median.isNativeApp();
// Returns: true or false
```

### Retrieve the current platform

Median JavaScript Bridge

```javascript JavaScript theme={null}
Median.getPlatform();
// Returns a promise that resolves to "web", "android", or "ios"
```

### OneSignal example demonstrating login and `oneSignalId` retrieval

Use the following example to integrate OneSignal with Median, sign in a user, and retrieve the `oneSignalId`.

Median JavaScript Bridge

```javascript JavaScript theme={null}
useEffect(() => {
 Median.onReady(async () => {
   const result = await Median.onesignal.login('test-user');
   if (result?.success) {
     const info = await Median.onesignal.info();
     console.log(info?.oneSignalId);
      // Store or use the oneSignalId as needed
   }})
}, []);
```


## Related topics

- [AgeSafety](https://docs.median.co/docs/age-safety.md)
- [JavaScript Bridge overview](https://docs.median.co/docs/javascript-bridge.md)
- [Detecting app usage](https://docs.median.co/docs/detecting-app-usage.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.