Skip to content

Error on structuredClone() + Svelte 5 store #15280

Answered by tomoam
ginpei asked this question in Q&A
Discussion options

You must be logged in to vote

please use $state.snapshot.

<script lang="ts">
	import { writable } from 'svelte/store';
	
	const props = $props(); // !?
	
	const obj = writable({ name: 'Yo' });
	console.log(1, $obj); // Object
	const obj2 = structuredClone($obj); // fine
	
	$obj = { name: 'Hey' };
	
	const snapshot = $state.snapshot($obj);

	console.log(2, snapshot);
	const obj3 = structuredClone(snapshot);
</script>

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@tomoam
Comment options

@ginpei
Comment options

@tomoam
Comment options

Answer selected by ginpei
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants