Severity: error | Blocks morph build: yes
morphShared was called inside a component (or another function), or at
module scope without export:
error : mx-shared-scope : `morphShared` may only appear at module scope
hint: Move `export const [value, setValue] = morphShared(...)` to the top of the file
Learn more: https://morph.levizr.com/docs/errors/mx-shared-scopeerror : mx-shared-scope : `morphShared` must be exported to be shared across modules
hint: Add `export` to the `const [value, setValue] = morphShared(...)` binding
Learn more: https://morph.levizr.com/docs/errors/mx-shared-scopemorphShared creates one store per window, shared by every importer in that window — the
opposite of `morphState`. That contract only holds if
the binding lives at module scope (exactly one declaration) and is exported
(importers bind to it by name). Inside a component it would run per render,
creating a fresh "shared" store every render — the worst of both worlds. The
linter enforces placement so the local/shared split is syntactic and
unmistakable. (Old string-key forms are a separate error:
mx-api-removed. For cross-window messaging, use
`morphEvent`, which is app-global.)
import { morphShared } from 'morph';
export default function App() {
// ❌ Inside a component — mx-shared-scope (use morphState here)
const [count, setCount] = morphShared(0);
return <div>{count}</div>;
}import { morphShared } from 'morph';
// ❌ Module scope but not exported — mx-shared-scope
const [count, setCount] = morphShared(0);
export default function App() {
return <div>{count}</div>;
}// ✅ Exported, module scope, single initial value
import { morphShared } from 'morph';
export const [count, setCount] = morphShared(0);
export default function App() {
return <div>{count}</div>;
}// ✅ Per-instance instead — morphState inside the component
import { morphState } from 'morph';
export default function App() {
const [count, setCount] = morphState(0);
return <div>{count}</div>;
}Steps:
export.morphState inside the
component body.morphShared<T>(initial) — two arguments is
the removed API (see mx-api-removed).morph check.Do not disable this rule. Misplaced shared state is the most common state bug Morph guards against.
morphState