Git Product home page Git Product logo

powerform-react's Introduction

powerform-react

A React hook for powerform

Syntax

usePowerform(schema, options?)

schema

Its a schema that is passed to powerform.

options

Its a option that is passed to powerform.

Usage

import React from "react";
import usePowerform from "powerform-react";
import "./styles.css";

function required(value) {
  if (!value) {
    return "This field is required.";
  }
}

function isPassword(value) {
  if (value.length < 8) {
    return "Password must be at least 8 characters long.";
  }
}

const schema = {
  email: required,
  password: [required, isPassword]
};

function submit(form) {
  return e => {
    e.preventDefault();
    form.validate();
  };
}

export default function App() {
  const form = usePowerform(schema);
  return (
    <div>
      <div className="label">Email</div>
      <input
        onInput={e => form.email.setData(e.target.value)}
        onChange={() => form.email.validate()}
      />
      <div className="error">{form.email.getError()}</div>
      <div className="label">Password</div>
      <input
        onInput={e => form.password.setData(e.target.value)}
        onChange={() => form.password.validate()}
      />
      <div className="error">{form.password.getError()}</div>
      <button onClick={submit(form)}>Login</button>
    </div>
  );
}

Checkout above example here.

powerform-react's People

Contributors

ludbek avatar

Watchers

 avatar  avatar

powerform-react's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.