react-final-form-hooks
Advanced tools
Comparing version
@@ -100,10 +100,22 @@ 'use strict'; | ||
}, [subscription]); | ||
var handleSubmit = react.useCallback(function (event) { | ||
if (event) { | ||
if (typeof event.preventDefault === 'function') { | ||
event.preventDefault(); | ||
} | ||
if (typeof event.stopPropagation === 'function') { | ||
event.stopPropagation(); | ||
} | ||
} | ||
return form.current.submit(); | ||
}, []); | ||
return _extends({}, state, { | ||
form: form.current | ||
form: form.current, | ||
handleSubmit: handleSubmit | ||
}); | ||
}; | ||
// | ||
exports.useField = useField; | ||
exports.useForm = useForm; |
@@ -1,2 +0,2 @@ | ||
import { useState, useEffect, useRef } from 'react'; | ||
import { useState, useEffect, useRef, useCallback } from 'react'; | ||
import { fieldSubscriptionItems, createForm, formSubscriptionItems } from 'final-form'; | ||
@@ -96,9 +96,21 @@ | ||
}, [subscription]); | ||
var handleSubmit = useCallback(function (event) { | ||
if (event) { | ||
if (typeof event.preventDefault === 'function') { | ||
event.preventDefault(); | ||
} | ||
if (typeof event.stopPropagation === 'function') { | ||
event.stopPropagation(); | ||
} | ||
} | ||
return form.current.submit(); | ||
}, []); | ||
return _extends({}, state, { | ||
form: form.current | ||
form: form.current, | ||
handleSubmit: handleSubmit | ||
}); | ||
}; | ||
// | ||
export { useField, useForm }; |
@@ -99,9 +99,21 @@ (function (global, factory) { | ||
}, [subscription]); | ||
var handleSubmit = react.useCallback(function (event) { | ||
if (event) { | ||
if (typeof event.preventDefault === 'function') { | ||
event.preventDefault(); | ||
} | ||
if (typeof event.stopPropagation === 'function') { | ||
event.stopPropagation(); | ||
} | ||
} | ||
return form.current.submit(); | ||
}, []); | ||
return _extends({}, state, { | ||
form: form.current | ||
form: form.current, | ||
handleSubmit: handleSubmit | ||
}); | ||
}; | ||
// | ||
exports.useField = useField; | ||
@@ -108,0 +120,0 @@ exports.useForm = useForm; |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("final-form")):"function"==typeof define&&define.amd?define(["exports","react","final-form"],r):r(e["react-final-form-hooks"]={},e.React,e.FinalForm)}(this,function(e,a,c){"use strict";function f(){return(f=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function s(e,r){if(null==e)return{};var n,t,u={},o=Object.keys(e);for(t=0;t<o.length;t++)n=o[t],0<=r.indexOf(n)||(u[n]=e[n]);return u}var l=c.fieldSubscriptionItems.reduce(function(e,r){return e[r]=!0,e},{}),p=c.formSubscriptionItems.reduce(function(e,r){return e[r]=!0,e},{});e.useField=function(e,r,n){var t=a.useState({}),u=t[0],o=t[1];a.useEffect(function(){return r.registerField(e,o,n||l)},[e,n]);var i=u||{},c=(i.blur,i.change,i.focus,i.value),f=s(i,["blur","change","focus","value"]);return delete f.name,{input:{name:e,value:c||"",onBlur:function(){return u.blur()},onChange:function(e){return u.change(e.target.value)},onFocus:function(){return u.focus()}},meta:f}},e.useForm=function(e){var r=e.subscription,n=s(e,["subscription"]),t=a.useRef(c.createForm(n)),u=a.useState({}),o=u[0],i=u[1];return a.useEffect(function(){return t.current.subscribe(i,r||p)},[r]),f({},o,{form:t.current})},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("final-form")):"function"==typeof define&&define.amd?define(["exports","react","final-form"],t):t(e["react-final-form-hooks"]={},e.React,e.FinalForm)}(this,function(e,a,c){"use strict";function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function l(e,t){if(null==e)return{};var n,r,u={},o=Object.keys(e);for(r=0;r<o.length;r++)n=o[r],0<=t.indexOf(n)||(u[n]=e[n]);return u}var p=c.fieldSubscriptionItems.reduce(function(e,t){return e[t]=!0,e},{}),b=c.formSubscriptionItems.reduce(function(e,t){return e[t]=!0,e},{});e.useField=function(e,t,n){var r=a.useState({}),u=r[0],o=r[1];a.useEffect(function(){return t.registerField(e,o,n||p)},[e,n]);var i=u||{},f=(i.blur,i.change,i.focus,i.value),c=l(i,["blur","change","focus","value"]);return delete c.name,{input:{name:e,value:f||"",onBlur:function(){return u.blur()},onChange:function(e){return u.change(e.target.value)},onFocus:function(){return u.focus()}},meta:c}},e.useForm=function(e){var t=e.subscription,n=l(e,["subscription"]),r=a.useRef(c.createForm(n)),u=a.useState({}),o=u[0],i=u[1];a.useEffect(function(){return r.current.subscribe(i,t||b)},[t]);var f=a.useCallback(function(e){return e&&("function"==typeof e.preventDefault&&e.preventDefault(),"function"==typeof e.stopPropagation&&e.stopPropagation()),r.current.submit()},[]);return s({},o,{form:r.current,handleSubmit:f})},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=react-final-form-hooks.umd.min.js.map |
{ | ||
"name": "react-final-form-hooks", | ||
"version": "1.0.0-alpha.0", | ||
"version": "1.0.0-alpha.1", | ||
"description": "React Hooks to bind to 🏁 Final Form's high performance subscription-based form state management engine", | ||
@@ -15,3 +15,2 @@ "main": "dist/react-final-form-hooks.cjs.js", | ||
"start": "nps", | ||
"test": "nps test", | ||
"doctoc": "doctoc README.md && doctoc docs/faq.md && prettier --write README.md && prettier --write docs/faq.md", | ||
@@ -43,5 +42,3 @@ "precommit": "lint-staged && npm start validate", | ||
"@babel/plugin-syntax-import-meta": "^7.0.0", | ||
"@babel/plugin-transform-flow-strip-types": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
@@ -53,2 +50,3 @@ "@types/react": "^16.4.16", | ||
"bundlesize": "^0.17.0", | ||
"cryptiles": ">=4.1.2", | ||
"doctoc": "^1.3.0", | ||
@@ -58,3 +56,3 @@ "eslint": "^5.6.1", | ||
"eslint-plugin-babel": "^5.2.1", | ||
"eslint-plugin-flowtype": "^2.50.3", | ||
"eslint-plugin-flowtype": "^3.2.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
@@ -65,7 +63,8 @@ "eslint-plugin-jsx-a11y": "^6.1.2", | ||
"final-form": "^4.10.0", | ||
"flow-bin": "^0.82.0", | ||
"glow": "^1.2.2", | ||
"hoek": ">=4.2.1", | ||
"husky": "^1.1.1", | ||
"jest": "^23.6.0", | ||
"lint-staged": "^7.3.0", | ||
"merge": ">=1.2.1", | ||
"np": "^3.0.4", | ||
"nps": "^5.9.3", | ||
@@ -82,3 +81,2 @@ "nps-utils": "^1.7.0", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-flow": "^1.1.1", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
@@ -85,0 +83,0 @@ "rollup-plugin-replace": "^2.1.0", |
@@ -18,3 +18,3 @@ # 🏁 React Final Form Hooks | ||
✅ 💥 [**773 bytes gzipped**](https://bundlephobia.com/result?p=react-final-form-hooks) 💥 | ||
✅ 💥 [**843 bytes gzipped**](https://bundlephobia.com/result?p=react-final-form-hooks) 💥 | ||
@@ -87,2 +87,11 @@ --- | ||
- [Examples](#examples) | ||
- [Simple Example](#simple-example) | ||
- [API](#api) | ||
- [`useField`](#usefield) | ||
- [`useForm`](#useform) | ||
- [Contributors](#contributors) | ||
- [Backers](#backers) | ||
- [Sponsors](#sponsors) | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
@@ -92,6 +101,5 @@ | ||
### [Simple Example](https://codesandbox.io/s/ww40y2m595) | ||
### [Simple Example](https://codesandbox.io/s/r4j042m694) | ||
Uses the built-in React inputs: `input`, `select`, and `textarea` to build a | ||
form with no validation. | ||
Shows how to create fields and attach them to `<input/>` elements. | ||
@@ -98,0 +106,0 @@ ## API |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29903
38.2%50
-1.96%306
12.5%142
5.97%