Socket
Socket
Sign inDemoInstall

@blockle/form

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blockle/form

Blockle Form


Version published
Weekly downloads
12
increased by1100%
Maintainers
1
Weekly downloads
 
Created
Source

@blockle/form

Install

yarn add @blockle/form

Usage

import React, { useState } from 'react';
import { Form, useField, useForm } from '@blockle/form';

interface UserForm {
  name: string;
}

const MyForm = () => {
  const form = useForm<UserForm>({
    async submit(data) {
      console.log('Form valid', data);
    },
  });

  // See form.values, form.erors

  return (
    <Form form={form}>
      <Input name="name" type="text" required />

      <button disabled={invalid || submitting}>Submit</button>
    </form>
  );
}

// Input.tsx
interface Props {
  name: string;
  value?: string;
  type: 'text' | 'password';
  required: boolean;
}

const Input: FC<Props> = ({ name, value, type, required }) => {
  const field = useField<string>({
    name,
    value,
    validate(value) {
      // Return string with "error code"
      if(required && !value.trim()) {
        return 'required';
      }

      return null;
    }
  });

  return (
    <input
      type={type}
      value={field.value}
      onChange={(event) => field.setValue(event.currentTarget.value)}
      onBlur={field.setTouched}
    />
  );
}

FAQs

Package last updated on 13 Jul 2021

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