import React, { forwardRef, useImperativeHandle } from 'react'; import { useFormSaver } from './useFormSaver'; import './react-html-attributes'; interface ReactFormSaverProps { children: React.ReactNode; debug?: boolean; storagePrefix?: string; ignoredAttributes?: string[]; autoSave?: boolean; className?: string; onSubmit?: (event: React.FormEvent) => void; onSave?: (element: HTMLElement) => void; onRestore?: (element: HTMLElement, value?: any) => void; } export interface ReactFormSaverRef { saveForm: () => void; restoreForm: () => void; clearForm: () => void; saveElementValue: (element: HTMLElement) => void; restoreElementValue: (element: HTMLElement) => any; clearElementValue: (element: HTMLElement) => void; } /** * React component version of JqueryFormSaver. * * Wraps form elements and automatically saves/restores their values to * web storage (localStorage) using an optional `storagePrefix` key. * * Usage notes: * - Inputs must have a `name` attribute to be saved/restored. * - The component restores values into the DOM. If you use controlled React * inputs (value + onChange) you should synchronize the restored DOM value * back into React state after calling `restoreForm()` (see example). * - Use the `ignoredAttributes` prop or the `no-save` attribute on an input to * exclude fields (for example OTP codes) from being stored. * * Examples: * * 1) Basic usage (uncontrolled inputs or inputs you don't need to sync into state): * * ```tsx * import React, { useRef } from 'react'; * import { ReactFormSaver, ReactFormSaverRef } from 'jquery-form-saver/react'; * * function ContactForm() { * const ref = useRef(null); * return ( * * *