Recall & Review
beginner
What is a custom store in Svelte?
A custom store in Svelte is a way to create your own reactive data source with custom logic for updating and subscribing, beyond the built-in writable or readable stores.
Click to reveal answer
beginner
Which function do you use to create a custom store in Svelte?
You create a custom store by writing a function that returns an object with a subscribe method, and optionally set and update methods for writable behavior.
Click to reveal answer
intermediate
Why would you use a custom store instead of a writable store in Svelte?
You use a custom store when you want to add extra logic like validation, side effects, or complex state management that writable stores don't support directly.
Click to reveal answer
beginner
What does the subscribe method in a custom store do?
The subscribe method lets components listen to changes in the store's value and reactively update when the value changes.
Click to reveal answer
intermediate
How can you add a cleanup function in a custom store?
Inside the subscribe method, you can return a function that runs when the last subscriber unsubscribes, useful for cleaning up resources like timers or event listeners.
Click to reveal answer
What must a custom store in Svelte always provide?
✗ Incorrect
The subscribe method is required for any Svelte store so components can listen to changes.
Which of these is NOT a reason to create a custom store?
✗ Incorrect
Styling components is unrelated to store logic; stores manage data and reactivity.
How do you notify subscribers about a new value in a custom store?
✗ Incorrect
Subscribers are functions that must be called with the updated value to trigger reactive updates.
What does the cleanup function returned by subscribe do?
✗ Incorrect
The cleanup function is called when no subscribers remain, to free resources.
Which Svelte store type is easiest to customize with extra logic?
✗ Incorrect
Custom stores let you define any logic you want, unlike built-in stores with fixed behavior.
Explain how to create a custom store in Svelte and why you might want to use one.
Think about how you share reactive data with extra control.
You got /4 concepts.
Describe the role of the subscribe method and the cleanup function in a custom Svelte store.
Focus on how subscriptions start and stop.
You got /4 concepts.