svelte-use-persist icon indicating copy to clipboard operation
svelte-use-persist copied to clipboard

How to clear ("invalidate") all data via code?

Open renatocaliari opened this issue 1 year ago • 1 comments

renatocaliari avatar Jun 25 '23 12:06 renatocaliari

By default, this package saves all form data to localStorage, so you could just use localStorage.removeItem('key') to remove all data for your specifed key

So if you have this form, for example:

<form
	use:persist={{
		key: 'my-form'
	}}
>
	<label for="title">Title</label>
	<input type="text" name="title" />
	<label for="content">Content</label>
	<textarea name="content" />
	<label for="date">Date</label>
	<input type="date" name="date" />
	<label for="phone">Phone</label>
	<input type="tel" name="phone" />
	<label for="email">Email</label>
	<input type="email" name="email" />
	<button type="submit">Save</button>
</form>

Then somewhere in your code you would use localStorage.removeItem('my-form') to clear all the data. Hope this helps.

fawaz-alesayi avatar Jun 26 '23 08:06 fawaz-alesayi