> **Status:** Published
> **Date:** 2026-09-12
> **Scope**: API Reference
> **Standard**: Memorio API Specification v5
>
---
# Classic `import` support

Memorio supports two styles: the explicit named-import style (recommended),
and the global side-effect entrypoint for when global access is explicitly desired.
Both share the same instances (one source of truth).

```typescript
// Explicit named imports (recommended for normal usage)
import { state } from 'memorio'
state.user = { name: 'Sara' }

// Global entrypoint (opt-in for global access)
import 'memorio/global'
state.user = { name: 'Sara' }
```

`state` in both examples is the exact same Proxy object.

---

## Why two styles?

| Style | When to use |
|-------|-------------|
| `import { state } from 'memorio'` | Explicit dependencies, tree-shakeable bundles, TypeScript IntelliSense |
| `import 'memorio/global'` | When global access is explicitly desired (legacy scripts, shell-style usage) |

---

## ESM named imports

All modules are available as named exports:

```typescript
import {
  state,
  store,
  session,
  cache,
  idb,
  observer,
  dispatch,
  message,
  devtools,
  logger
} from 'memorio'
```

Platform helpers:

```typescript
import {
  isBrowser,
  isNode,
  isDeno,
  isEdge,
  getCapabilities,
  createContext,
  listContexts,
  deleteContext
} from 'memorio'
```

Internal utilities (for tests/debug):

```typescript
import internal, { propertyName } from 'memorio'
import { setContext, getContext } from 'memorio'
```

Default export (the public `memorio` namespace):

```typescript
import memorio from 'memorio'
memorio.help()   // dev-only introspection
```

---

## CJS usage

```javascript
const { state, store, memorio } = require('memorio')
```

---

## React / useObserver

`useObserver` works the same way via named import:

```tsx
import { useObserver } from 'memorio/react'
import { state } from 'memorio'

function Counter() {
  const [, forceUpdate] = useReducer(x => x + 1, 0)

  useObserver(forceUpdate, [state.counter])

  return <div>Count: {state.counter}</div>
}
```

---

## Context isolation

```typescript
import { createContext, listContexts, deleteContext, isolate } from 'memorio'

const ctx = createContext('tenant-123')
ctx.state.user = { name: 'Isolated' }
ctx.store.set('settings', { theme: 'dark' })

listContexts() // ['tenant-123']
deleteContext('tenant-123')
```

---

## Same-instance guarantee

Named exports point to the same instances as the global entrypoint. Mutating via a named export mutates the same proxy instance that `import 'memorio/global'` would install on `globalThis`, and vice versa.

```typescript
import { state } from 'memorio'

state.importedFlag = true
console.debug(globalThis.state?.importedFlag) // true (when global entrypoint is loaded)
```

---

## Migration to explicit imports

If you previously used `import 'memorio'` for global access, migrate to either:

```typescript
// Option A: named imports (recommended)
import { state, store } from 'memorio'

// Option B: explicit global entrypoint (opt-in)
import 'memorio/global'
// state, store, etc. are now on globalThis
```
