Giter VIP home page Giter VIP logo

react-final-form-hooks's Introduction

๐Ÿ React Final Form Hooks

React Final Form Hooks

Backers on Open Collective Sponsors on Open Collective NPM Version NPM Downloads Build Status codecov.io styled with prettier

โœ… Zero dependencies

โœ… Only peer dependencies: React and ๐Ÿ Final Form

โœ… Opt-in subscriptions - only update on the state you need!

โœ… ๐Ÿ’ฅ 773 bytes gzipped ๐Ÿ’ฅ


๐Ÿ‘จโ€๐Ÿ”ฌ EXPERIMENTAL ๐Ÿ‘ฉโ€๐Ÿ”ฌ

Need I say this? The React Hooks API is still very experimental and not recommended for production code.

Installation

npm install --save react-final-form-hooks final-form

or

yarn add react-final-form-hooks final-form

Getting Started

๐Ÿ React Final Form Hooks is the leanest possible way to connect ๐Ÿ Final Form to React, to acheive subscriptions-based form state management using the Observer pattern.

โš ๏ธ This library will re-render your entire form on every state change, as you type. โš ๏ธ

If performance is your goal, you are recommended to use ๐Ÿ React Final Form. Also, that library does many other things for you, like managing checkbox and radio buttons properly. RFFHooks leaves all of that work to you. By default, ๐Ÿ React Final Form Hooks subscribes to all changes, but if you want to fine tune your form, you may specify only the form state that you care about for rendering your gorgeous UI.

Here's what it looks like in your code:

import { useForm, useField } from 'react-final-form-hooks'

const MyForm = () => {
  const { form, handleSubmit, values, pristine, submitting } = useForm({
    onSubmit, // the function to call with your form values upon valid submit
    validate // a record-level validation function to check all form values
  })
  const firstName = useField('firstName', form)
  const lastName = useField('lastName', form)
  return (
    <form onSubmit={handleSubmit}>
      <div>
        <label>First Name</label>
        <input {...firstName.input} placeholder="First Name" />
        {firstName.meta.touched &&
          firstName.meta.error && <span>{firstName.meta.error}</span>}
      </div>
      <div>
        <label>Last Name</label>
        <input {...lastName.input} placeholder="Last Name" />
        {lastName.meta.touched &&
          lastName.meta.error && <span>{lastName.meta.error}</span>}
      </div>
      <button type="submit" disabled={pristine || submitting}>
        Submit
      </button>
    </form>
  )
}

Table of Contents

Examples

Shows how to create fields and attach them to <input/> elements.

API

The following can be imported from react-final-form-hooks.

useField

Returns an object similar to FieldRenderProps.

useForm

Returns an object similar to FormRenderProps.


Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

react-final-form-hooks's People

Contributors

erikras avatar

Watchers

 avatar

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.