selectors
Various selectors located in redux-forms/selectors
allow you to see the current state of your form.
All the selectors are memoized. Sleep well knowing you won't get any unnecessary re-renders or expensive computations.
getValues: (form: string, state: Object) => Object
- Returns values of all your current fields
getErrors: (form: string, state: Object) => Object
- Returns errors of all your current fields
isValid: (form: string, state: Object) => boolean
true
if your form contains no errors
isTouched: (form: string, state: Object) => boolean
true
if any field is touched
isDirty: (form: string, state: Object) => boolean
true
if any field is dirty
isSubmitting: (form: string, state: Object) => boolean
true
if your form is currently being submitted
Example
Say we have a form called myform
and want to know it's values and validity in a MyComponent
component:
import { getValues, isValid } from 'redux-forms/selectors`;
// ... your component
export default connect(state => ({
values: getValues('myform', state),
valid: isValid('myform', state),
}))(MyComponent);
You can then for example use values
for validation functions that depend on other values of your form.