@typed-web/form-store
v0.2.0
Published
Framework-agnostic form state management with type-safe paths
Maintainers
Readme
@typed-web/form-store
Framework-agnostic form state management with type-safe paths and reactive updates.
Installation
npm install @typed-web/form-storeExports
createFormStore- Create a form store instanceFormStore- TypeScript type for storeTuplePaths,TuplePathValue- TypeScript utility types
Usage
import { createFormStore } from "@typed-web/form-store";
type User = {
name: string;
email: string;
address: {
city: string;
state: string;
};
};
const store = createFormStore<User>({
name: "",
email: "",
address: {
city: "",
state: "",
},
});
// Type-safe path access
store.set(["address", "city"], "San Francisco");
const city = store.get(["address", "city"]);
// Subscribe to changes
const unsubscribe = store.subscribe(["address", "city"], (value) => {
console.log("City changed:", value);
});
// Batch updates
store.batch(() => {
store.set(["name"], "John");
store.set(["email"], "[email protected]");
});License
MIT
