Day 21 createContext
Santa's naughty-and-nice list app needs notifications — but threading a notification function through every layer of components is like untangling a mile of Christmas lights! That's where createContext comes in.
The old way was a bit of a ceremony: import getContext and setContext from Svelte, create a Symbol to avoid string collisions, then export typed wrapper functions just to get proper TypeScript support. Ho-ho-hold my eggnog — there's a better way!
With createContext, you call it once with your type, and it hands you back a tuple of [getContext, setContext] functions, already typed and ready to use. No symbols, no strings, no boilerplate. In your layout, set the notification function; in any deeply nested component, call getContext() and it just works!
It's like Santa having a direct hotline to every elf in the workshop — no matter how deep in the toy factory they are. When Rich Harris gets added to the nice list, that notification pops up at the top of the screen instantly!