Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
use-redux-form
Advanced tools
With use-redux-form
, any kind of React form components can be possible to use
simply with Redux store object.
input tag
, select tag
.<DatePicker {...getFieldProps('createdAt')} />
npm install use-redux-form
// useReduxForm
const { isValidated, isDisabled, values, errors, handleSubmit, getFieldProps } =
useReduxForm();
// storePath
useReduxForm({ storePath: 'this-is-store-path' }); // v1
useReduxForm('this-is-store-path', {}); // v2
// disable - onDisable
useReduxForm({ disable: () => isLoading }); // v1
useReduxForm('this-is-store-path', { onDisable: () => isLoading }); // v2
// exclude (new)
useReduxForm('this-is-store-path', { exclude: [] }); // v2
// debug (new)
useReduxForm('this-is-store-path', { debug: true }); // v2
// initialValues (new) - only work when onChange is not given
useReduxForm(
'this-is-store-path',
{},
{
/* here */
},
); // v2
// getFieldProps
const { value, selected, disabled, name, onChange } = getFieldProps('a.2.b', {
key: () => {}, // no more
isRequired: true, // no more
include: [], // new
exclude: [], // v1, v2
name: 'my-name-is', // v1, v2
});
useReduxForm(options)
const {
isValidated,
isDisabled,
values, // state of redux store
errors, // return object from validate function
handleSubmit,
getFieldProps
} = useReduxForm('user.form', {
/**
* Exclude props from `getFieldProps` returns (global)
* @default []
* @type {Array}
*/
exclude: [],
/**
* Enable or Disable fields
* @default F
* @see {@link https://ramdajs.com/docs/#F}
* @return {Boolean}
*/
onDisable: () => isLoading,
/**
* Form validate
* @default always({})
* @see {@link https://ramdajs.com/docs/#always}
* @param {Object} values
* @return {Object} empty object = valid
*/
validate: (values) => {
const errors = {}
if (!values.username) {
errors.username = 'required!'
}
return errors;
},
/**
* Transform values before reaching to `value`, `onChange`.
* @default (o) => o.value
* @param {String} name fieldPath
* @param {*} value
* @return {*} a component asks specific data type
*/
transform: ({ name, value }) => {
if (name === 'nil-to-zero') {
return '0'
}
if (name === 'date') {
return new Date(value)
}
return value;
},
/**
* General `onChange` prop for all components using `getFieldProps`.
* @default null
* @see {@link https://ramdajs.com/docs/#identity}
* @param {String} name fieldPath (getFieldProps)
* @param {*} value value that you typed or stored in Redux store
*/
onChange: ({ name, value }) => {
if (name === 'A') {
actionA(value)
}
actionB(value)
},
/**
* Submit function
* @default @default identity
* @see {@link https://ramdajs.com/docs/#identity}
* @param {Object} values
* @param {Object} errors
*/
onSubmit: ({ values, errors }) => {
if (!isEmpty(errors)) {
return Object.values(errors).forEach((value) => {
if (value) {
invalidAlert(value);
}
});
}
submit(values);
},
/**
* Display current state log on console
* @default falss
*/
debug: true
}, {
/*
- initialValues
- work only when onChange is not given (experimental feature)
*/
})
return (
<Field {...getFieldProps('username')} />
<Button onClick={handleSubmit}>Submit<Button>
);
getFieldProps(fieldPath, options?)
A function return form field props
// reducer/user.js
const initialState = {
form: {
username: '',
someObj: {
password: '',
},
someArray1: ['hello', 'world'],
someParentState: {
someArray2: ['world', 'hello'],
list: [
{
id: 1,
type: 'A',
name: 'X',
},
{
id: 2,
type: 'B',
name: 'Y',
},
{
id: 3,
type: 'C',
name: 'Z',
},
],
},
},
};
const { value, selected, disabled, name, onChange } = getFieldProps(
/**
* fieldPath
* @type {String}
* @required
*/
'someParentState.list.0.type', // => 'A'
{
/**
* Field name
* @type {String}
* @default fieldPath
*/
name: 'userid',
/**
* Include props what excluded global (local)
* @type {Array}
* @default []
*/
include: ['name'],
/**
* Exclude props from `getFieldProps` returns (local)
* @type {Array}
* @default []
*/
exclude: ['selected'],
/**
* Find value
* (let's say 'someParentState.list' is `fieldPath`)
* @param {Array|Object} fieldState object from `fieldPath`
* @param {Array|Object} state
* @return {String|Number}
*/
find: (fieldState, state) => {
const { type } = givenState.find((item) => item.id === 2);
return type; // B
},
/**
* Force transform stop
* @type {Boolean}
*/
transform: false,
},
);
MIT
FAQs
Connect form and Redux store through React hook
The npm package use-redux-form receives a total of 19 weekly downloads. As such, use-redux-form popularity was classified as not popular.
We found that use-redux-form 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.