npm.io
0.0.5 • Published 2 years ago

react-inbox-link

Licence
MIT
Version
0.0.5
Deps
0
Size
9 kB
Vulns
0
Weekly
0

The React bindings for the LinkToInbox.com API offering both component and hook interfaces encapsulating the standard Web Component and JavaScript API interfaces respectively.

This package also has TypeScript support for a smoother integration.

npm install react-inbox-link

Usage

The component API:

import { InboxLink } from 'react-inbox-link'

function Example() {
  return (
    <InboxLink
      publishableKey="pk_YOUR_KEY"
      recipientAddress="user@example.com"
    />
  )
}

The hook API:

import { useInboxLink } from 'react-inbox-link'

function Example() {
  const inboxLink = useInboxLink('pk_YOUR_KEY', {
    recipientAddress: 'user@example.com',
  })

  switch (inboxLink.type) {
    case 'loading':
      return <p>Loading…</p>
    case 'link_not_available':
      if (inboxLink.error) {
        console.error(inboxLink.error)
      }
      return null
    case 'link_data':
      const { link, icon, providerName } = inboxLink.data
    // Render how you'd like
  }
}

Keywords