Skip to content

Commit

Permalink
Fix jaredpalmer#3948 - Changing state was also causing change of init…
Browse files Browse the repository at this point in the history
…ial value
  • Loading branch information
DeveloperRaj authored Jan 30, 2024
1 parent 0f960aa commit 16b9673
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/formik/src/Formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
setIn,
setNestedObjectValues,
} from './utils';
import cloneDeep from 'lodash/cloneDeep';

type FormikMessage<Values> =
| { type: 'SUBMIT_ATTEMPT' }
Expand Down Expand Up @@ -173,10 +174,10 @@ export function useFormik<Values extends FormikValues = FormikValues>({

const [, setIteration] = React.useState(0);
const stateRef = React.useRef<FormikState<Values>>({
values: props.initialValues,
errors: props.initialErrors || emptyErrors,
touched: props.initialTouched || emptyTouched,
status: props.initialStatus,
values: cloneDeep(props.initialValues),
errors: cloneDeep(props.initialErrors) || emptyErrors,
touched: cloneDeep(props.initialTouched) || emptyTouched,
status: cloneDeep(props.initialStatus),
isSubmitting: false,
isValidating: false,
submitCount: 0,
Expand Down

0 comments on commit 16b9673

Please sign in to comment.