npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tawasal/react

v0.0.7

Published

tawasal sdk for react development

Downloads

30

Readme

npm npm Bundle Size Bundle Size

This library provides a set of React hooks to integrate with the Tawasal SuperApp API, allowing you to interact with various functionalities such as fetching user data, handling clipboard operations, scanning QR codes, and more.

Installation

npm i @tawasal/react

Usage

useTawasal

Fetches user information, user photo, and user link.

Example

import React from 'react';
import { useTawasal } from '@tawasal/react';

const UserProfile = () => {
  const { user, avatar, userLink, error, isLoading } = useTawasal();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      {user && (
        <div>
          <h2>User Info</h2>
          <p>Name: {user.name}</p>
          <p>ID: {user.id}</p>
        </div>
      )}
      {avatar && <img src={avatar} alt="User Photo" />}
      {userLink && <p>User Link: {userLink}</p>}
    </div>
  );
};

export default UserProfile;

useContacts

Allows selecting contacts and fetching their details including avatar URLs.

Example

import React, { useState } from 'react';
import { useContacts } from '@tawasal/react';

const ContactSelector = () => {
  const { contacts, isLoading, error, triggerSelect } = useContacts();

  return (
    <div>
      <button onClick={() => triggerSelect('Select a contact')}>
        Select Contacts
      </button>
      {isLoading && <div>Loading...</div>}
      {error && <div>Error: {error.message}</div>}
      {contacts && (
        <ul>
          {contacts.map(contact => (
            <li key={contact.userId}>
              {contact.name} - {contact.photoUrl && <img src={contact.photoUrl} alt="Avatar" />}
            </li>
          ))}
        </ul>
      )}
    </div>
  );
};

export default ContactSelector;

useClipboard

Reads the content of the clipboard.

Example

import React from 'react';
import { useClipboard } from '@tawasal/react';

const ClipboardReader = () => {
  const { clipboard, isLoading, error, updateClipboard } = useClipboard();

  return (
    <div>
      <button onClick={updateClipboard}>Read Clipboard</button>
      {isLoading && <div>Loading...</div>}
      {error && <div>Error: {error.message}</div>}
      {clipboard && <p>Clipboard Content: {clipboard}</p>}
    </div>
  );
};

export default ClipboardReader;

usePhoneNumber

Prompts the user to share their phone number.

Example

import React from 'react';
import { usePhoneNumber } from '@tawasal/react';

const PhoneNumberPrompt = () => {
  const { phone, isLoading, error, triggerPhonePrompt } = usePhoneNumber();

  return (
    <div>
      <button onClick={() => triggerPhonePrompt('We need your phone number for verification')}>
        Get Phone Number
      </button>
      {isLoading && <div>Loading...</div>}
      {error && <div>Error: {error.message}</div>}
      {phone && <p>Phone Number: {phone}</p>}
    </div>
  );
};

export default PhoneNumberPrompt;

useQR

Shows the QR code scanner and returns the scanned QR code.

Example

import React, { useEffect } from 'react';
import { useQR } from '@tawasal/react';

const QRScanner = () => {
    const {qr, isLoading, error, triggerScan, closeScan} = useQR();

    useEffect(()=> {
        // don't forget that your code and user can close scan. So if you recieved data you wanted
        // from user, you can close scan faster then user to provide better UX.
        if (!!qr) {
            closeScan()
        }
    }, [qr])

    return (
        <div>
            <button onClick={triggerScan}>Scan QR Code</button>
            <button onClick={closeScan}>Close Scanner</button>
            {isLoading && <div>Loading...</div>}
            {error && <div>Error: {error.message}</div>}
            {qr && <p>QR Code: {qr}</p>}
        </div>
    );
};

export default QRScanner;

useTawasalSDK

Provides additional Tawasal SDK functionalities such as haptic feedback, opening a destination, closing the app, and sharing content.

Example

import React from 'react';
import { useTawasalSDK } from '@tawasal/react';

const TawasalActions = () => {
  const { haptic, open, closeApp, share } = useTawasalSDK();

  return (
    <div>
      <button onClick={() => haptic('light')}>Haptic Feedback</button>
      <button onClick={() => open('destination')}>Open Destination</button>
      <button onClick={closeApp}>Close App</button>
      <button
        onClick={() =>
          share({
            text: 'Check out this link!',
            url: 'https://example.com',
          })
        }
      >
        Share
      </button>
    </div>
  );
};

export default TawasalActions;

Fixes for compabilty

Next.js

error: ESM packages need to be imported

add esm support to your next.js config

experimental: {
  esmExternals: "loose" 
}

License

Distributed under the MIT License. See LICENSE for more information.