Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

picoform

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

picoform

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

picoform

Overview

Tiny React hook for managing form state. That's it. 🤏

  • Headless form 🤖
  • Super lightweight
  • Easy to use 🤘
  • Compatible with your favorite UI framework and validation package 💜
  • TypeScript supported 🌞

Installation

Install package :

yarn add picoform
# or
npm install picoform

How to use

Basic usage

import { useForm } from 'picoform';

export default function App() {
  const { as, handleSubmit, values } = useForm();

  const onSubmit = () => console.log(values);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...as('firstname')} />
      <input {...as('lastname')} />
      <button type="submit">Submit</button>
    </form>
  );
}

With initial values

import { useForm } from 'picoform';

const initialValues = {
  firstname: 'John',
  lastname: 'Doe',
};

export default function App() {
  const { as, handleSubmit, values } = useForm({ initialValues });

  const onSubmit = () => console.log(values);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...as('firstname')} />
      <input {...as('lastname')} />
      <button type="submit">Submit</button>
    </form>
  );
}

With yup package

import { useForm } from 'picoform';
import * as yup from 'yup';

const schema = yup.object().shape({
  username: yup.string().required(),
  password: yup
    .string()
    .min(8)
    .required(),
});

export default function App() {
  const { as, handleSubmit, values } = useForm();

  const onSubmit = async () => {
    try {
      await schema.validate(values);
      console.log(values);
    } catch (err) {
      console.log(err);
    }
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...as('username')} type="text" />
      <input {...as('password')} type="password" />
      <button type="submit">Submit</button>
    </form>
  );
}

With material-ui package

import { useForm } from 'picoform';
import TextField from '@mui/material/TextField';

export default function App() {
  const { as, handleSubmit, values } = useForm();

  const onSubmit = () => console.log(values);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <TextField {...as('firstname')} />
      <TextField {...as('lastname')} />
      <Button type="submit">Submit</Button>
    </form>
  );
}

FAQs

Package last updated on 26 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc