Skip to content

Push Module

The Push module checks notification permission and retrieves the device push token.

import { Push } from '@shopgate/native-modules';
import { useEffect, useState } from 'react';
import { Push } from '@shopgate/native-modules';
export function PushTokenStatus() {
const [token, setToken] = useState(null);
useEffect(() => {
const loadToken = async () => setToken(await Push.getToken());
loadToken();
}, []);
return <p>{token ? 'Push enabled' : 'No push token'}</p>;
}
const permissionGranted = await Push.hasPermission();

Returns Promise<boolean>.

const token = await Push.getToken();

Returns Promise<string | null>.

Fires when a push notification is received while it can be delivered to the web layer. The native notification payload is available as event.detail.

import { useEffect } from 'react';
import { Push } from '@shopgate/native-modules';
export function PushListener() {
useEffect(() => {
const handlePush = (event) => console.log('Push received', event.detail);
Push.addEventListener('pushReceived', handlePush);
return () => Push.removeEventListener('pushReceived', handlePush);
}, []);
return null;
}