Socket
Socket
Sign inDemoInstall

picoform

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    picoform


Version published
Weekly downloads
2
decreased by-50%
Maintainers
1
Install size
14.5 kB
Created
Weekly downloads
 

Readme

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

Last updated on 26 May 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc