Skip to main content
ReactiveDict provides a reactive dictionary of key-value pairs, similar to Session but scoped to your usage. It’s ideal for component-level reactive state.

Installation

Overview

ReactiveDict provides:
  • Reactive key-value storage - Like Session, but scoped
  • Hot Code Push persistence - Optionally preserve state across reloads
  • EJSON values - Store any EJSON-serializable value
  • Fine-grained reactivity - Only invalidate when specific keys change
  • Multiple instances - Create as many dictionaries as needed

Package Information

  • Version: 1.3.2
  • Summary: Reactive dictionary
  • Dependencies: tracker, ejson, mongo (weak), reload (weak)
  • Export: ReactiveDict

Basic Usage

Creating a ReactiveDict

name
string
Optional name for the dictionary. Named dictionaries are preserved across Hot Code Push.
initialValue
object
Optional object with initial key-value pairs

Setting Values

Getting Values

Constructor

Anonymous Dictionary

Named Dictionary

Methods

set(key, value) or set(object)

Set one or more key-value pairs:
key
string
The key to set (when setting single value)
value
any
The value to set (must be EJSON-serializable)

get(key)

Get a value and establish reactive dependency:
key
string
required
The key to retrieve
Returns the value, or undefined if key doesn’t exist.

setDefault(key, value)

Set a value only if the key doesn’t exist:

all()

Get all key-value pairs as an object:
Calling all() creates a dependency on every key in the dictionary.

clear()

Remove all keys:

delete(key)

Remove a specific key:

equals(key, value)

Reactively check if a key equals a value:
equals() is more efficient than get() when you only care about a specific value.

Reactivity

Key-Level Reactivity

ReactiveDict invalidates only computations that depend on changed keys:

Reactive Patterns

Common Patterns

Pattern: Form State Management

Pattern: Component State

Pattern: Loading States

Pattern: Feature Flags

Using with React

Persistence

Hot Code Push Persistence

Named ReactiveDict instances are automatically preserved across hot code push:
Persistence only works on the client and only for hot code push, not full page reloads.

Manual Serialization

Comparison with Session

ReactiveDict

Session (deprecated)

Performance Tips

Use equals() for boolean checks - More efficient than get() when checking specific values
Avoid all() in computations - Creates dependency on every key
Batch updates - Set multiple keys at once with object syntax

Debugging

reactive-var

Single reactive values

tracker

Reactive computation system

session

Global reactive dictionary (deprecated)

Source Code