Stores allow components to “react” when the content of the store is changed.
If the store is declared “globally” (not in a components) any scripts can access it and interact with it.
Globally declared storeIn component declared store
Global variable
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
✅
❌
✅
Any
Similar to store, a global variable act as a central point of storage.
But global variable are not reactive, so you have to implement yourself a method to update the component.
Svelte event
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
❌
✅
❌
Child → Parent
The data sharing only works in the direction child to parent.
get/setContext
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
❌
❌
❌
Parent → Children
(Can be bi-directional and reactive, see below)
The data sharing only works in the direction parent to children (and children of children).
Context with normal variableContext with store
Bi-directional and reactive
Props
One-way binding (down)
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
❌
✅
❌
Parent → Child
The parent is providing the value to its child.
Changing the value in the parent will be reflected in the child.
Two-way binding
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
❌
✅
✅
Parent ↔ Child
The parent is providing a variable that can be written by the child.
Changes made in the parent will be reflected and the child, changes made in children will be send to its parent
One-way binding (up)
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
❌
✅
❌
Child → Parent
The parent is providing a function that will update the parent scope from its children
DOM event
In Component
In Javascript/TypeScript
Reactive
Bi-directional
Direction
✅
❌
✅
❌
Child → Parents
Use native DOMEvent to bubble up data from a child to any parent willing to listen to it.