diff --git a/content/4-component-composition/5-context/svelte5/UserProfile.svelte b/content/4-component-composition/5-context/svelte5/UserProfile.svelte index 7eb05322..244b3493 100644 --- a/content/4-component-composition/5-context/svelte5/UserProfile.svelte +++ b/content/4-component-composition/5-context/svelte5/UserProfile.svelte @@ -8,7 +8,7 @@

My Profile

Username: {user.value.username}

Email: {user.value.email}

- diff --git a/content/4-component-composition/5-context/svelte5/createUserState.js b/content/4-component-composition/5-context/svelte5/createUserState.js index a76e93bc..85253dd3 100644 --- a/content/4-component-composition/5-context/svelte5/createUserState.js +++ b/content/4-component-composition/5-context/svelte5/createUserState.js @@ -1,14 +1,12 @@ export default function createUserState(initial) { - let user = $state(initial); + let username = $state(initial.username); return { - get value() { - return user; + ...initial, + get username() { + return username; }, - updateUsername(newUsername) { - user = { - ...user, - username: newUsername, - }; + set username(value) { + username = value; }, }; }