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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@teonord/useform

v1.0.0

Published

React form hook for managing form state, validation, and HTTP requests. TypeScript support, file uploads, and Inertia.js-like API. Standalone alternative to useForm.

Readme

@teonord/useform

A standalone React hook similar to Inertia's useForm, supporting both TypeScript and JavaScript implementations.

Features

  • 🚀 Simple and intuitive API
  • 📦 Standalone (no Inertia.js dependency)
  • 🔷 Full TypeScript support with type definitions
  • 📝 Automatic FormData handling for file uploads
  • ⚡ Built-in error handling
  • 🎯 Supports all HTTP methods (GET, POST, PUT, PATCH, DELETE)

Installation

npm install @teonord/useform

or

yarn add @teonord/useform

or

pnpm add @teonord/useform

Usage

JavaScript

import useForm from '@teonord/useform'

function MyComponent() {
  const { data, setData, errors, processing, post, reset } = useForm({
    name: '',
    email: '',
  })

  const handleSubmit = (e) => {
    e.preventDefault()
    post('/api/users', {
      onSuccess: (response) => {
        console.log('Success!', response)
        reset()
      },
      onError: (error) => {
        console.error('Error:', error)
      },
    })
  }

  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        value={data.name}
        onChange={(e) => setData('name', e.target.value)}
      />
      {errors.name && <span>{errors.name}</span>}

      <input
        type="email"
        value={data.email}
        onChange={(e) => setData('email', e.target.value)}
      />
      {errors.email && <span>{errors.email}</span>}

      <button type="submit" disabled={processing}>
        {processing ? 'Submitting...' : 'Submit'}
      </button>
    </form>
  )
}

TypeScript

import useForm from '@teonord/useform'
import type { UseFormReturn } from '@teonord/useform'

interface FormData {
  name: string
  email: string
  age?: number
}

function MyComponent() {
  const { data, setData, errors, processing, post, reset }: UseFormReturn<FormData> = 
    useForm<FormData>({
      name: '',
      email: '',
    })

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault()
    post('/api/users', {
      onSuccess: (response) => {
        console.log('Success!', response)
        reset()
      },
      onError: (error) => {
        console.error('Error:', error)
      },
    })
  }

  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        value={data.name}
        onChange={(e) => setData('name', e.target.value)}
      />
      {errors.name && <span>{errors.name}</span>}

      <input
        type="email"
        value={data.email}
        onChange={(e) => setData('email', e.target.value)}
      />
      {errors.email && <span>{errors.email}</span>}

      <button type="submit" disabled={processing}>
        {processing ? 'Submitting...' : 'Submit'}
      </button>
    </form>
  )
}

API

useForm<T>(initialData?: T)

Returns an object with the following properties and methods:

Properties

  • data: T - The current form data
  • errors: Record<string, string | string[]> - Validation errors from the server
  • processing: boolean - Whether a request is currently in progress
  • wasSuccessful: boolean - Whether the last request was successful

Methods

  • setData(key: keyof T, value: any) - Update a specific field in the form data
  • reset(...fields: (keyof T)[]) - Reset the form. If no fields are provided, resets all fields to initial values
  • post(url: string, options?: UseFormOptions<T>) - Submit a POST request
  • get(url: string, options?: UseFormOptions<T>) - Submit a GET request
  • put(url: string, options?: UseFormOptions<T>) - Submit a PUT request
  • patch(url: string, options?: UseFormOptions<T>) - Submit a PATCH request
  • delete(url: string, options?: UseFormOptions<T>) - Submit a DELETE request

UseFormOptions<T>

Options object for HTTP methods:

interface UseFormOptions<T> {
  onSuccess?: (response: any) => void
  onError?: (error: any) => void
  headers?: Record<string, string>
}

File Uploads

The hook automatically detects file uploads and uses FormData:

const { data, setData, post } = useForm({
  name: '',
  avatar: null,
})

// Set a file
setData('avatar', e.target.files[0])

// Or multiple files
setData('avatar', e.target.files)

// Submit - automatically uses FormData
post('/api/upload', {
  onSuccess: (response) => {
    console.log('File uploaded!', response)
  },
})

License

MIT