Skip to content

Instantly share code, notes, and snippets.

@ryanzec
Created April 23, 2024 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanzec/d5f5d61fe484fabbb6649bfd8afc6459 to your computer and use it in GitHub Desktop.
Save ryanzec/d5f5d61fe484fabbb6649bfd8afc6459 to your computer and use it in GitHub Desktop.
create store per property of object svelte
const buildPropertyWritables = <TFormData extends object>(data: TFormData) => {
const writables: Record<string, Writable<any>> = {};
Object.keys(data).forEach((key) => {
writables[key] = writable(data[key as keyof TFormData]);
})
return writables as Record<keyof TFormData, Writable<any>>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment