Gathering detailed insights and metrics for @softmg/effector-react-form
Gathering detailed insights and metrics for @softmg/effector-react-form
Gathering detailed insights and metrics for @softmg/effector-react-form
Gathering detailed insights and metrics for @softmg/effector-react-form
npm install @softmg/effector-react-form
Typescript
Module System
Node Version
NPM Version
TypeScript (95.99%)
JavaScript (4.01%)
Total Downloads
2,140
Last Day
15
Last Week
55
Last Month
165
Last Year
2,140
321 Commits
2 Watching
1 Branches
8 Contributors
Minified
Minified + Gzipped
Latest Version
4.3.1
Package Id
@softmg/effector-react-form@4.3.1
Unpacked Size
178.24 kB
Size
33.79 kB
File Count
23
NPM Version
10.1.0
Node Version
20.9.0
Publised On
06 Mar 2024
Cumulative downloads
Total Downloads
Last day
200%
15
Compared to previous day
Last week
31%
55
Compared to previous week
Last month
-38.4%
165
Compared to previous month
Last year
0%
2,140
Compared to previous year
1
5
47
Clone based on effector-react-form
Connect your forms with state manager
1# Yarn 2yarn add @softmg/effector-react-form 3 4# NPM 5npm install --save @softmg/effector-react-form
1import { createForm } from '@softmg/effector-react-form'; 2 3const form = createForm<Values>({ 4 initialValues: { 5 userName: '', 6 email: '', 7 password: '', 8 repeatPassword: '', 9 }, 10 onSubmit: ({ values }) => // your post method, 11});
Set this form to our jsx
1import { useForm } from '@softmg/effector-react-form'; 2 3const validateFields = (value) => { 4 if (!value) return 'Field is required'; 5 if (value.length < 4) return 'Minimum of 4 characters'; 6 return undefined; 7}; 8 9const Form = () => { 10 const { controller, handleSubmit, submit } = useForm({ form: formSignIn }); 11 return ( 12 <form onSubmit={handleSubmit}> 13 <Input label="Name" controller={controller({ name: 'userName', validate: validateFields })} /> 14 <Input label="Name" controller={controller({ name: 'email', validate: validateFields })} /> 15 <Input label="Password" controller={controller({ name: 'password', validate: validateFields })} /> 16 <Input label="Repeat password" controller={controller({ name: 'repeatPassword', validate: validateFields })} /> 17 <button onClick={submit}> 18 submit 19 </button> 20 </form> 21 ); 22};
Custom Input component
1const Input = ({ controller, label }) => { 2 const { input,isShowError, error } = controller(); 3 4 return ( 5 <div className="input-wrap"> 6 <label>{label}</label> 7 <input {...input} value={input.value || ''} className={'input'} /> 8 {isShowError && <div className="input-error-message">{error}</div>} 9 </div> 10 ); 11};
name: form name
validate: function, for validation values of the form.
Example:
1const validateForm = ({ values }) => { 2 const errors = {}; 3 4 if (values.newPassword !== values.repeatPassword) { 5 errors.newPassword = 'passwordsDontMatch'; 6 errors.repeatPassword = 'passwordsDontMatch'; 7 } 8 9 if (values.newPassword && values.newPassword === values.oldPassword) { 10 errors.newPassword = 'passwordMustDiffer'; 11 } 12 13 return errors; 14};
mapSubmit: a function that transforms data that received from the form fields before passing it to the onSubmit function.
onSubmit: a function that fires on a form submit even.
onSubmitGuardFn: before the onSubmit function is executed, the value of this field is checked. By default, it contains a predicate function that checks if there are validation errors in form fields. If there are no errors, it returns true and onSubmit is triggered. You can pass your own predicate function that will accept the values of the form fields and an object with meta.
onChange: a function that`s triggered when the form fields change. onChangeGuardFn: before the onChange function is executed, the value of this field is checked. By default, it contains a predicate function that checks if there are validation errors in form fields. If there are no errors, it will return true and onChange will be fired. You can pass your own predicate function that will accept the values of the form fields and an object with meta.
initalValues: an object with initial values of your form fields.
Example:
1const initialValues = { 2 name: "John", 3 lastName: "Smith" 4}
initialMeta: an object with initial values of your form fields.
resetOuterErrorsBySubmit: takes true / false. Determines whether outer form errors should be cleared on the onSubmit event. The default is true.
resetOuterErrorByOnChange: takes true / false. Determines whether outer form errors should be cleared on the onChange event. The default is true.
No vulnerabilities found.
No security vulnerabilities found.