This demo has four separate React islands accessing the same central application (the obligatory counter) via their own contexts.
createApp()
creates the application around a nanostore atom.island-context
manages app and context creation (In reality each island would likely be it's own context with an entirely distinct global name. Here the islands are instances of the same component—so the contexts are managed by one global Map).
CounterUI
is the "Control Panel" for the application. TheuseApp()
hook gives the component access to the application.Island
is the component tree for a single island.
The index page shows four identical UIs, each one bound to the same application.
- Derived from the Astro
with-nanostores
example.
Clone the repo:
$ cd context-cross-context
$ npm i
$ npm run dev