0.1.4-alpha.0 • Published 3 years ago

@faumally/react v0.1.4-alpha.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@faumally/react

React hooks for form handling backed by state machines

Usage

import useFaumally from "@faumally/react";

type Form = {
  age: number;
  email: string;
  address: string;
  lastName: string;
  firstName: string;
};

const config = { required: true };

const createUser = (user: any) => Promise.resolve();

const { submit, handlers, subscribe } = useFaumally<Form>({
  schema: {
    email: config,
    lastName: config,
    firstName: config,
    address: "string",
    age: {
      ...config,
      initialValue: 0,
    },
  },
  onSubmit(data) {
    return createUser(data);
  },
});