A set of helpers helping persist the state of form based on Final Form
Currently the only source for obtaining this library is to build it from source as it is available from no package registry yet.
$ npm install
$ npm test # check if everying is OK
$ npm run build
A mutator loading raw form values from a storage:
const form = createForm({
mutators: {
loadValues: loadValues(options)
/* other mutators */
}
/* rest of the config */
});
Subscriber that saves raw form values to a storage on each call.
form.subscribe(saveValues(options), { /* subscription */ });
Storages are objects implementing DataStorage
interface that can be passed to the helpers through options. They are effectively drivers for persistence
A thin wrapper over browser's Storage
API, using JSON.parse
and JSON.stringify
for (de-)serialization.
A static factory method that creates BrowserStorage
object with the underlying storage passed as an argument. It accepts window.localStorage
, window.sessionStorage
or anything with compatible API.
const storage = BrowserStorage.useWith(window.localStorage);
const storage = BrowserStorage.useWith(window.sessionStorage);
There are persistence helpers (subscriber and mutator) planned for:
- field value
- form state
- field state
In addition:
- clearing stored data
define-form
compatibility- support for React Native's
AsyncStorage
(as a separate package or through optional dependencies)
There's an issue with nesting arbitraryInternalFormState
within arbitraryMutableState
. It's circumvented with explicit casting, though it's not completely typesafe. Low priority due to being present only in tests.
Not guaranteed work smoothly with define-form
, which is an alternative, generics-based typings for final-form
. final-form-storage
does not support generic values object โ it's type is any
. On the roadmap.