You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I certainly think there's a better way to write this than setting each control individually. You can set the form value as a whole, in a single action. To what @Balastrong said, just grab the value you don't want to reset, and make sure that is the value you set on top of your initial state. My approach would be to do this in your own action, something like
// dispatch action you've created - obviously name whatever makes sense to youthis.store.dispatch(softResetForm())/* in your reducer */on(actions.softResetForm,(state)=>{// get the current value for `stage`const{ stage }=state.formState.value;// create a value from your initial form state, with `stage` overridden with the value aboveconstsoftResetValue={ ...DOCTRANS_FORM_INITIAL_STATE.value, stage };// use `reset()` on your formState if, if you want reset to pristine - if not leave out// use `setValue()` on the entire formState, providing the value defined aboveconstformState=setValue(reset(state.formState),softResetValue);// update your statereturn{ ...state, formState };})
Hey,
hope this is the right place to post it.
I have the following reducer.ts:
When i want to reset the form i can call:
But i would like to reset it except of the stage.
What i do now:
But i think there must be a better way. Maybe some reducer which says "reset all but keep stage".
Thanks
The text was updated successfully, but these errors were encountered: