├── .babelrc ├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .gitignore ├── .npmignore ├── .nvmrc ├── .prettierignore ├── .prettierrc.cjs ├── LICENSE ├── README.md ├── dist ├── index.d.ts ├── index.es.js └── index.umd.js ├── lib ├── core.js ├── index.js ├── tests │ ├── components │ │ ├── TestForm.jsx │ │ ├── defaultValues.js │ │ ├── options.js │ │ └── schema.js │ ├── core.test.js │ ├── useForm-arrays │ │ ├── UnitTestForm.jsx │ │ └── useForm-arrays.test.jsx │ ├── useForm.test.jsx │ ├── useStableRef.test.jsx │ ├── yupResolver.test.js │ └── zodResolver.test.js ├── useForm.jsx ├── useStableRef.jsx ├── yupResolver.js └── zodResolver.js ├── package.json ├── public └── index.d.ts ├── stats.html ├── vite.config.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/react" 5 | ], 6 | "plugins": [ 7 | "@babel/plugin-proposal-class-properties" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | .prettierrc.js 4 | .eslintrc.js 5 | env.d.ts -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | settings: { 3 | react: { 4 | version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use. 5 | }, 6 | 'import/resolver': { 7 | node: { 8 | paths: ['src'], 9 | extensions: ['.js', '.jsx', '.ts', '.tsx'], 10 | }, 11 | }, 12 | }, 13 | env: { 14 | browser: true, 15 | es6: true, 16 | node: true, 17 | }, 18 | extends: ['eslint:recommended', 'airbnb', 'prettier', 'eslint-config-prettier'], 19 | plugins: ['react-hooks'], 20 | rules: { 21 | 'import/no-extraneous-dependencies': 0, 22 | 'jsx-a11y/anchor-is-valid': 0, 23 | 'jsx-a11y/click-events-have-key-events': 0, 24 | 'jsx-a11y/no-static-element-interactions': 0, 25 | 'jsx-a11y/no-noninteractive-element-interactions': 0, 26 | 'react/jsx-filename-extension': 0, 27 | 'import/no-cycle': 0, 28 | 'no-console': 'off', 29 | 'no-shadow': 'off', 30 | 'no-plusplus': 'off', 31 | 'react/jsx-indent': [1, 'tab', { checkAttributes: false, indentLogicalExpressions: true }], 32 | 'react/jsx-props-no-spreading': 0, 33 | 'react/jsx-one-expression-per-line': 0, 34 | 'react/react-in-jsx-scope': 0, // vite does this automatically 35 | 'no-param-reassign': 0, 36 | 'react/forbid-prop-types': [0], 37 | 'react/prop-types': [0], 38 | 'react/require-default-props': [0], 39 | 'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks 40 | 'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies 41 | }, 42 | }; 43 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js text eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist-ssr 4 | *.local 5 | 6 | # binaries 7 | bin/ 8 | 9 | # editors 10 | *.swp 11 | .idea/ 12 | .vs/ 13 | .vscode/ 14 | .DS_Store 15 | 16 | # libs 17 | node_modules/* 18 | 19 | TODO.txt -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v21.7.3 -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | .prettierrc.js 4 | -------------------------------------------------------------------------------- /.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | //"module": "commonjs" 2 | 3 | module.exports = { 4 | parser: 'babel', 5 | printWidth: 170, // wrap lines at 6 | tabWidth: 4, // indentation 7 | useTabs: true, // tabs instead of spaces 8 | semi: true, // add semicolons to end of statements 9 | singleQuote: true, // force single quotes where possible 10 | quoteProps: 'as-needed', // only required for some props 11 | jsxSingleQuote: false, // jsx prop quotes 12 | trailingComma: 'all', // es5? 13 | bracketSpacing: true, // { foo: bar } instead of {foo: bar} 14 | jsxBracketSameLine: false, // https://prettier.io/docs/en/options.html#jsx-brackets 15 | arrowParens: 'avoid', // x => {} 16 | // "rangeStart": 0, 17 | // "rangeEnd": 0, 18 | // "parser": "babel", 19 | // "filepath": "", 20 | requirePragma: false, 21 | //"insertPragma": false, 22 | proseWrap: 'preserve', 23 | htmlWhitespaceSensitivity: 'css', 24 | embeddedLanguageFormatting: 'auto', 25 | endOfLine: 'auto', 26 | vueIndentScriptAndStyle: false, 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # useForm 2 | React forms hook, lightweight alternative to existing frameworks. 3 | 4 | [See full demo](https://k7s4y.csb.app/) 5 | 6 | Concerned about performance? Try this demo, optimized with with React.memo: 7 | 8 | [400 form inputs](https://7izw4f.csb.app/) 9 | 10 | ## Installation 11 | ```bash 12 | npm install --save @rvision/use-form 13 | ``` 14 | or 15 | ```bash 16 | yarn add @rvision/use-form 17 | ``` 18 | 19 | ## Quickstart: basic usage 20 | ```jsx 21 | const defaultValues = { 22 | firstName: '', 23 | lastName: '', 24 | email: '', 25 | agree: false 26 | }; 27 | 28 | const Form = () => { 29 | const { 30 | register, 31 | handleSubmit, 32 | } = useForm({ 33 | defaultValues 34 | }); 35 | 36 | const onSubmit = values => console.log(values); // handles form submit: call API, etc. 37 | 38 | return ( 39 |