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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@craft-native/react

v0.0.358

Published

React bindings for Craft framework

Readme

@craft-native/react

React bindings for the Craft framework. Provides hooks to access native functionality in your React applications.

Installation

npm install @craft-native/react
# or
yarn add @craft-native/react
# or
pnpm add @craft-native/react

Usage

Core Hooks

useCraft

Access the Craft API:

import { useCraft } from '@craft-native/react';

function App() {
  const { craft, isReady } = useCraft();

  if (!isReady) {
    return <div>Loading...</div>;
  }

  return <div>Craft is ready!</div>;
}

usePlatform

Get platform information:

import { usePlatform } from '@craft-native/react';

function PlatformInfo() {
  const { platform, loading } = usePlatform();

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      Platform: {platform?.platform}
      Version: {platform?.version}
    </div>
  );
}

useDeviceInfo

Get device information:

import { useDeviceInfo } from '@craft-native/react';

function DeviceInfo() {
  const { deviceInfo } = useDeviceInfo();

  return (
    <div>
      Model: {deviceInfo?.model}
      OS: {deviceInfo?.os_version}
    </div>
  );
}

UI Hooks

useToast

Show toast notifications:

import { useToast } from '@craft-native/react';

function ToastExample() {
  const { showToast } = useToast();

  return (
    <button onClick={() => showToast('Hello!', 'short')}>
      Show Toast
    </button>
  );
}

useHaptic

Trigger haptic feedback:

import { useHaptic } from '@craft-native/react';

function HapticButton() {
  const { haptic } = useHaptic();

  return (
    <button onClick={() => haptic('impact_medium')}>
      Tap Me
    </button>
  );
}

usePermission

Request permissions:

import { usePermission } from '@craft-native/react';

function CameraPermission() {
  const { granted, request, loading } = usePermission('camera');

  return (
    <div>
      {granted === null && (
        <button onClick={request} disabled={loading}>
          Request Camera Access
        </button>
      )}
      {granted && <div>Camera access granted!</div>}
      {granted === false && <div>Camera access denied</div>}
    </div>
  );
}

Window Management

useWindow

Manage the application window:

import { useWindow } from '@craft-native/react';

function WindowControls() {
  const { maximize, minimize, toggleFullscreen, isFullscreen } = useWindow();

  return (
    <div>
      <button onClick={maximize}>Maximize</button>
      <button onClick={minimize}>Minimize</button>
      <button onClick={toggleFullscreen}>
        {isFullscreen ? 'Exit' : 'Enter'} Fullscreen
      </button>
    </div>
  );
}

System Integration

useTray

Manage system tray icon:

import { useTray } from '@craft-native/react';

function TrayManager() {
  const { create, setMenu } = useTray();

  useEffect(() => {
    create('/path/to/icon.png', 'My App');
    setMenu([
      { id: 'show', label: 'Show Window' },
      { id: 'quit', label: 'Quit', type: 'normal' },
    ]);
  }, []);

  return null;
}

useNotification

Send system notifications:

import { useNotification } from '@craft-native/react';

function NotificationExample() {
  const { send } = useNotification();

  const notify = () => {
    send({
      title: 'Hello!',
      body: 'This is a notification',
    });
  };

  return <button onClick={notify}>Notify</button>;
}

File System

useFileSystem

Interact with the file system:

import { useFileSystem } from '@craft-native/react';

function FileEditor() {
  const { readFile, writeFile, loading, error } = useFileSystem();
  const [content, setContent] = useState('');

  const load = async () => {
    const data = await readFile('/path/to/file.txt');
    setContent(data);
  };

  const save = async () => {
    await writeFile('/path/to/file.txt', content);
  };

  return (
    <div>
      <textarea value={content} onChange={(e) => setContent(e.target.value)} />
      <button onClick={load}>Load</button>
      <button onClick={save}>Save</button>
      {loading && <div>Loading...</div>}
      {error && <div>Error: {error.message}</div>}
    </div>
  );
}

Database

useDatabase

Work with SQLite databases:

import { useDatabase } from '@craft-native/react';

function TodoList() {
  const { query, execute } = useDatabase('/path/to/db.sqlite');
  const [todos, setTodos] = useState([]);

  useEffect(() => {
    loadTodos();
  }, []);

  const loadTodos = async () => {
    const results = await query('SELECT * FROM todos');
    setTodos(results);
  };

  const addTodo = async (title: string) => {
    await execute('INSERT INTO todos (title) VALUES (?)', [title]);
    await loadTodos();
  };

  return (
    <ul>
      {todos.map((todo) => (
        <li key={todo.id}>{todo.title}</li>
      ))}
    </ul>
  );
}

HTTP Requests

useHttp

Make HTTP requests:

import { useHttp } from '@craft-native/react';

function ApiExample() {
  const { fetch, loading } = useHttp();
  const [data, setData] = useState(null);

  const loadData = async () => {
    const result = await fetch('https://api.example.com/data');
    setData(result);
  };

  return (
    <div>
      <button onClick={loadData} disabled={loading}>
        Load Data
      </button>
      {data && <pre>{JSON.stringify(data, null, 2)}</pre>}
    </div>
  );
}

Event Handling

useCraftEvent

Listen to Craft events:

import { useCraftEvent } from '@craft-native/react';

function EventListener() {
  useCraftEvent('app.ready', () => {
    console.log('App is ready!');
  });

  useCraftEvent('window.close', () => {
    console.log('Window is closing');
  });

  return <div>Listening to events...</div>;
}

Utility Hooks

useIsMobile

Check if running on mobile:

import { useIsMobile } from '@craft-native/react';

function ResponsiveComponent() {
  const isMobile = useIsMobile();

  return <div>{isMobile ? 'Mobile View' : 'Desktop View'}</div>;
}

useIsDesktop

Check if running on desktop:

import { useIsDesktop } from '@craft-native/react';

function DesktopOnly() {
  const isDesktop = useIsDesktop();

  if (!isDesktop) return null;

  return <div>Desktop-only features</div>;
}

API Reference

See the TypeScript definitions for complete API documentation.

License

MIT