Repository: jaredpalmer/formik (ts)

Issue:
`arrayHelpers.push` pushes reference which causes unwanted side effects
## Current Behavior
<!-- If applicable, add screenshots to help explain your problem. -->
When using `arrayHelpers.push` with an object it keeps reference of that object until it's used
![formik push reference](https://user-images.githubusercontent.com/7680511/44468032-9a25c480-a624-11e8-9ba4-54ac8291c023.gif)

## Steps to Reproduce
<!-- Steps to reproduce the behavior: -->
Use `arrayHelpers.push` with an object multiple times, update any input
## Expected behavior
<!-- A clear and concise description of what you expected to happen. -->
keep all inputs seperate
## Suggested solution(s)
<!-- How could we solve this bug? What changes would need to made to Formik? -->
Just use clone depp when pushing
## Additional context
<!-- Add any other context about the problem here.  -->


**CodeSandbox Link**:
https://codesandbox.io/s/jzx4nypz5
---
<!-- PLEASE FILL THIS OUT -->
- Formik Version: 1.0.3
- React Version: 16.4.2
- TypeScript Version:
- Browser and Version:
- OS: 
- Node Version:
- Package Manager and Version:


Pull request description:
fix array helpers push side effect issue
Fixes side effect that happen when using object in `arrayProps.push`
Use `cloneDeep` when pushing new value in FieldArray 

| Before | After |
|:-:|:-:|
| ![formik push reference](https://user-images.githubusercontent.com/7680511/44469479-e292b180-a627-11e8-88c2-5f970de4df34.gif) |  ![fix 841](https://user-images.githubusercontent.com/7680511/44469490-eb838300-a627-11e8-8336-1e865e21964d.gif) |



fixes #841 

Patch:
diff --git a/src/FieldArray.tsx b/src/FieldArray.tsx
index 499523c..2d27c6a 100644
--- a/src/FieldArray.tsx
+++ b/src/FieldArray.tsx
@@ -1,4 +1,5 @@
 import * as React from 'react';
+import cloneDeep from 'lodash.clonedeep';
 import { connect } from './connect';
 import {
   FormikContext,
@@ -125,7 +126,7 @@ class FieldArrayInner<Values = {}> extends React.Component<
 
   push = (value: any) =>
     this.updateArrayField(
-      (array: any[]) => [...(array || []), value],
+      (array: any[]) => [...(array || []), cloneDeep(value)],
       false,
       false
     );


Test patch:
diff --git a/test/FieldArray.test.tsx b/test/FieldArray.test.tsx
index 67f5380..6a88731 100644
--- a/test/FieldArray.test.tsx
+++ b/test/FieldArray.test.tsx
@@ -95,6 +95,37 @@ describe('<FieldArray />', () => {
       const expected = ['jared', 'andrea', 'brent', 'jared'];
       expect(formikBag.values.friends).toEqual(expected);
     });
+    it('should push clone not actual referance', () => {
+      let personTemplate = { firstName: '', lastName: '' };
+      let formikBag: any;
+      let arrayHelpers: any;
+      ReactDOM.render(
+        <TestForm
+          initialValues={{ people: [] }}
+          render={(props: any) => {
+            formikBag = props;
+            return (
+              <FieldArray
+                name="people"
+                render={arrayProps => {
+                  arrayHelpers = arrayProps;
+                  return null;
+                }}
+              />
+            );
+          }}
+        />,
+        node
+      );
+
+      arrayHelpers.push(personTemplate);
+      expect(
+        formikBag.values.people[formikBag.values.people.length - 1]
+      ).not.toBe(personTemplate);
+      expect(
+        formikBag.values.people[formikBag.values.people.length - 1]
+      ).toMatchObject(personTemplate);
+    });
   });
 
   describe('props.pop()', () => {