Push Module
The Push module checks notification permission and retrieves the device push token.
import { Push } from '@shopgate/native-modules';Example React component
Section titled “Example React component”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>;}hasPermission()
Section titled “hasPermission()”const permissionGranted = await Push.hasPermission();Returns Promise<boolean>.
getToken()
Section titled “getToken()”const token = await Push.getToken();Returns Promise<string | null>.
Events
Section titled “Events”pushReceived
Section titled “pushReceived”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;}
