react-redux-forms中actions.submit()与actions.submitFields的区别咨询
actions.submit() and actions.submitFields() in react-redux-form Hey there! I totally get the confusion here—react-redux-form's docs do gloss over this distinction a bit. Let’s break down their key differences, plus clarify what’s happening in your test scenario.
Core Differences
1. Target Scope
actions.submit(model): This is for submitting an entire form model (like your'feature'form). It triggers the full form-level submission flow, including:- Running validation for all fields in the form
- Updating the entire form’s state (e.g.,
submitting,submitSucceeded,submitFailed) - Dispatching form-wide actions like
rrf/submitStart,rrf/submitSuccess, orrrf/submitFail
actions.submitFields(fieldsArray, submitPromise): This is designed for submitting a subset of form fields, not the whole form. It focuses only on the specific fields you list, and doesn’t touch the overall form’s submission state.
2. Triggered Actions & State Changes
When you use submit() on your full 'feature' model, you’ll see a full sequence of form-focused actions that update the form’s submission lifecycle state.
In your test, you called actions.submit('feature.firstName', somePromise)—this is actually misusing submit() by passing a single field as the model. React-redux-form treats this as a tiny, standalone "form" for that field, but since there’s no full form configuration tied to 'feature.firstName', it only dispatches the rrf/addIntent action (marking that field has a submission intent) without completing a full submission flow.
If you’d used actions.submitFields(['feature.firstName'], somePromise) instead, you’d see it handle that specific field’s submission: running field-level validation, dispatching actions tied to that field’s pending state, and resolving/rejecting your passed promise.
3. Use Cases
- Use
submit()when you need to submit the entire form (e.g., a "Save Form" button that validates all fields and updates the overall form submission state). - Use
submitFields()for partial/subset submissions: like auto-saving a single field as the user types, or submitting a section of a large form without triggering the full form’s validation or state updates.
内容的提问来源于stack exchange,提问作者johnwick0831

