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

@insoutt/punku

v1.1.0

Published

Simple React hook form for Laravel

Readme

@insoutt/punku

punku is a React hook for easy form handling and validation when consuming Laravel APIs.


Installation

To add punku to your project, simply run:

npm install @insoutt/punku
# or
yarn add @insoutt/punku

Usage

Here's a detailed example demonstrating how you can use the useForm hook effectively with TypeScript:

import React from 'react';
import { useForm } from '@insoutt/punku';

interface LoginForm {
  email: string;
  password: string;
}

interface LoginResponse {
  message: string;
  user: {
    id: number;
    email: string;
  };
}

const LoginComponent = () => {
  const { data, setData, post, processing, errors } = useForm<LoginForm>({
    email: '',
    password: '',
  });

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();

    post<LoginResponse>('/api/login', {
      onSuccess: (responseData) => {
        console.log('Login successful:', responseData.message);
      },
      onValidationError: (message) => {
        console.error('Validation Error:', message);
      },
      onError: ({ errors }) => {
        console.error('Validation errors:', errors);
      },
    });
  };

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

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

      <button type="submit" disabled={processing}>
        {processing ? 'Logging in...' : 'Login'}
      </button>
    </form>
  );
};

API Reference

useForm Hook

Properties

| Property | Description | Type | | -------------------- | ------------------------------------------------------- | -------------------------------------- | | data | Current form data. | TForm | | isDirty | Indicates if form data has changed from initial values. | boolean | | errors | Form validation errors. | Partial<Record<keyof TForm, string>> | | hasErrors | Boolean indicating presence of validation errors. | boolean | | processing | Boolean indicating if form submission is in progress. | boolean | | progress | Upload progress event (if applicable). | Progress \| null | | wasSuccessful | Indicates if the last submission was successful. | boolean | | recentlySuccessful | Indicates if the submission was recently successful. | boolean |

Methods

| Method | Description | | ------------------------------- | ----------------------------------------------------------- | | setData(key, value) | Update specific form fields. | | setData(newData) | Replace entire form data. | | setData(prevData => newData) | Update form data using previous state. | | setDefaults() | Reset form data to initial values. | | setDefaults(key, value) | Set default value for a specific field. | | setDefaults({ field: value }) | Set multiple default values. | | reset(...fields) | Reset specific fields or entire form to defaults. | | clearErrors(...fields) | Clear validation errors from specific fields or all fields. | | setError(field, message) | Set validation error for a specific field. | | setError({ field: message }) | Set multiple field errors. | | transform(callback) | Modify form data before sending. | | cancel() | Abort an ongoing HTTP request. |

HTTP Methods

Each method (get, post, put, patch, delete) supports the following configuration options:

| Option | Description | Type | | ------------------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | url | Request endpoint. | string | | withFormData | Formats data as FormData. Required for file uploads. | boolean | | onStart | Called when request begins. | () => void | | onFinish | Called after request completion. | () => void | | onSuccess | Called on successful response. | (data: TRequest, response?: AxiosResponse<TRequest>) => void | | onValidationError | Called when server returns validation errors. If is declared and there is a validation message onError is not called | (message: string) => void | | onError | Called on request failure. | (error?: { errors?: Partial<Record<keyof TForm, string>>; requestError: AxiosError }) => void |


Inspiration

punku was inspired by the Inertia.js Form Helper for React. While Inertia.js tightly integrates with Laravel's routing and server-side rendering, it has limitations making traditional API requests. punku addresses these limitations by providing a flexible solution designed specifically to interact directly with Laravel APIs, supporting a broader variety of React project structures and architectures.


License

MIT License