Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
a very easy react hooks form component. can replace the antd form component.
https://mengxiong10.github.io/easy-formx/example.html
$ npm install easy-formx --save
import { useFormx, Formx, FormxItem } from 'easy-formx';
import 'easy-formx/dist/index.css';
const rules = {
name: { required: true, message: 'required', trigger: 'blur' },
description: { required: true, message: 'required', trigger: 'blur' }
};
const initialValue = {
name: 'easy-formx',
description: 'a very easy react hooks form component'
};
export default function Basic() {
const { bindFormx, value, validate } = useFormx(initialValue, rules);
const submit = () => {
validate().then((data) => {
console.log(data);
});
};
return (
<Formx labelWidth="100px">
<FormxItem label="Name" {...bindFormx('name')}>
<Input />
</FormxItem>
<FormxItem label="Description" {...bindFormx('description')}>
<Input />
</FormxItem>
<FormxItem>
<Button type="primary" onClick={submit}>
submit
</Button>
</FormxItem>
</Formx>
);
}
const { bindFormx, value, validate, setFieldsValue, setFieldsError, getField } = useFormx(
initialValue
);
current form value
A function that returns the appropriate props that can be spread on the FormxItem
.
After bind FormxItem
by bindFormx, value(or other property defined by valuePropName) onChange(or other property defined by trigger) props will be added to first child comoponent.
<FormxItem label="name" {...bindFormx('name')}>
<input type="text" />
</FormxItem>
Set the value of fields
setFieldsValue({ name: 'name', age: 'age' });
Set the error of fields
setFieldsError({ name: new Error('required') });
validate all fields, return promise
validate().then();
get the binding field value and error;
// basic
const [value, error] = getField('name');
// just update the wrapper compoennt when the binding value changed
const expensiveItem = useMemo(
() => (
<FormxItem label="name" {...bindFormx('name')}>
<ExpensiveComponent />
</FormxItem>
),
getField('name')
);
Prop | Description | Type | Default |
---|---|---|---|
labelPosition | position of label | 'right' | 'left' | 'top' | 'right' |
labelWidth | width of label | string|number | - |
labelSuffix | suffix of label | string | ':' |
Prop | Description | Type | Default |
---|---|---|---|
label | The label text | string | - |
labelStyle | The label style | object | - |
trigger | prop of listen children node value change | string | 'onChange' |
valuePropName | prop of children node value | string | 'value' |
Copyright (c) 2019-present xiemengxiong
FAQs
a react form component to replace antd form
The npm package easy-formx receives a total of 8 weekly downloads. As such, easy-formx popularity was classified as not popular.
We found that easy-formx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.