Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/formik-persist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface PersistProps {
name: string;
debounce?: number;
isSessionStorage?: boolean;
normalize?: (values: any) => any;
}

class PersistImpl extends React.Component<
Expand All @@ -15,6 +16,7 @@ class PersistImpl extends React.Component<
> {
static defaultProps = {
debounce: 300,
normalize: (values: any) => values,
};

saveForm = debounce((data: FormikProps<{}>) => {
Expand All @@ -36,7 +38,9 @@ class PersistImpl extends React.Component<
? window.sessionStorage.getItem(this.props.name)
: window.localStorage.getItem(this.props.name);
if (maybeState && maybeState !== null) {
this.props.formik.setFormikState(JSON.parse(maybeState));
const parsed = JSON.parse(maybeState);
const data = this.props.normalize ? this.props.normalize(parsed) : parsed;
this.props.formik.setFormikState(data);
}
}

Expand Down