Skip to content

Commit 88e1725

Browse files
author
Micael Rodrigues
committed
wip
1 parent 6f2697d commit 88e1725

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/hooks/use-form.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ const valuesReducer = (state, action) => {
113113
newValue = payload.value;
114114
}
115115

116+
if (newValue === state[payload.field]) {
117+
return state;
118+
}
119+
116120
return {
117121
...state,
118122
[payload.field]: newValue
@@ -152,6 +156,10 @@ const metaReducer = (state, action) => {
152156
};
153157

154158
case actionTypes.SET_FIELD_VALUE:
159+
if (state[payload.field]?.dirty) {
160+
return state;
161+
}
162+
155163
return {
156164
...state,
157165
[payload.field]: {
@@ -294,7 +302,7 @@ const formReducer = (validate: Object => FieldErrors, stateReducer: (state: Form
294302
const fieldsMeta = metaReducer(state.fields.meta, action);
295303
const isSubmitting = isSubmittingReducer(state.isSubmitting, action);
296304
const submitStatus = submitStatusReducer(state.submitStatus, action);
297-
const fieldsErrors = errorsReducer({
305+
const fieldsErrors = fieldsValues === state.fields.values ? state.fields.errors : errorsReducer({
298306
action,
299307
state: state.fields.errors,
300308
validate,

0 commit comments

Comments
 (0)