1.1.0 • Published 3 years ago

@sutiles/forumu v1.1.0

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

React Forumu

Simple and powerful form handler for React

Important

At the moment, this library can only be used as a react hook.

Sections

Installation

Install as package with npm:

npm install @sutiles/forumu

Setup

Example

import React from "react";
import { useForumu } from "@sutiles/forumu";

export default function Login() {
  const { fields, props } = useForumu({
    initValues: {
      email: "",
      password: "",
    },
    onSubmit: (fields, event) => {
      console.log(fields.email, fields.password, event)
    }
  });

  return (
    <form {...props.form}>
      <input type="text" name="email" id="email" {...props.input} />
      <input type="text" name="password" id="password" {...props.input} />
      <button type="submit">Login</button>
    </form>
  );
}

Settings

KeyTypeRequiredDescription
initValuesobjectYesInitial values of fields.
onSubmitfunctionYesCallback to be called when the form's submit is fired. Receives two arguments, fields and event.
onChangefunctionNoCallback to be called when change event is fired. Receives current event as argument.
validatorfunctionNoCallback to be called when values of fields has been changed or when the form's submit event is fired. Receives fields and errors as arguments.
filterfunctionNoFunction for input data validation, if it returns false, the fields will not be updated. Receives entry and event as arguments.
preventErrorbooleanNoPrevent onSubmit callback if it contains errors. By default it is set to true.
discriminatebooleanNoAssigns the value of the fields depending on the type of input. If it is of type checkbox, the assigned value will be boolean, if it is text it will be of type string. By default it is set to true.

Values

KeyTypeDescription
fieldsobjectAll field values.
touchedobjectAll touched fields.
errorsobjectAll errors fields.
resetFormfunctionReset form fields, receives field keys as parameters.
propsobjectContains the respective form and input props.
1.1.0

3 years ago

1.0.0

3 years ago