Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
76d734d
docs: document Signal class for v2
bowheart Jul 23, 2025
3b226d1
docs: document `injectSignal` injector for v2
bowheart Jul 23, 2025
25f5442
docs: document `ZeduxNode` class for v2
bowheart Jul 23, 2025
b85ec47
docs: document `AtomInstance` class for v2
bowheart Jul 23, 2025
dda386e
docs: document `Ecosystem` class for v2
bowheart Jul 24, 2025
7399aa8
docs: document `AtomTemplate` class for v2
bowheart Jul 24, 2025
8feebc5
docs: document glossary for v2
bowheart Jul 24, 2025
08ab6e6
docs: document `atom` factory for v2
bowheart Jul 24, 2025
15ab275
docs: document `AtomApi` class for v2
bowheart Jul 24, 2025
cd3e5c1
docs: document `api` factory for v2
bowheart Jul 24, 2025
98223ed
docs: document `SelectorInstance` class for v2
bowheart Jul 24, 2025
142c2f6
docs: document `AtomProvider` component for v2
bowheart Jul 24, 2025
66a18e6
docs: document `EcosystemProvider` component for v2
bowheart Jul 24, 2025
a653a5e
docs: document `ion` factory for v2
bowheart Jul 24, 2025
a4bc835
docs: document `MappedSignal` class for v2
bowheart Jul 24, 2025
040c9b2
docs: document `useEcosystem` hook for v2
bowheart Jul 24, 2025
81d257f
docs: document `createEcosystem` factory for v2
bowheart Jul 24, 2025
ecf9bd9
docs: document `injectEcosystem` injector for v2
bowheart Jul 24, 2025
2a4365c
docs: document `useAtomContext` hook for v2
bowheart Jul 24, 2025
4f03145
docs: document `useAtomInstance` hook for v2
bowheart Jul 24, 2025
09f5137
docs: document `useAtomSelector` hook for v2
bowheart Jul 25, 2025
f4797fc
docs: document `SelectorTemplate` type for v2
bowheart Jul 25, 2025
6a96082
docs: document `useAtomState` hook for v2
bowheart Jul 25, 2025
12d4322
docs: document `useAtomValue` hook for v2
bowheart Jul 25, 2025
f4b616f
docs: document `injectAtomInstance` for v2
bowheart Jul 25, 2025
df53ac7
docs: document `injectAtomState` injector for v2
bowheart Jul 25, 2025
95aaf09
docs: document `injectAtomValue` injector for v2
bowheart Jul 25, 2025
97b1ea9
docs: document `injectCallback` injector for v2
bowheart Jul 25, 2025
94d8f41
docs: document `injectEffect` injector for v2
bowheart Jul 31, 2025
e9e1309
docs: document `injectHydration` injector for v2
bowheart Aug 1, 2025
9b64c91
docs: document `injectMappedSignal` for v2
bowheart Aug 4, 2025
e261b14
docs: document `injectMemo` for v2
bowheart Aug 5, 2025
71368db
docs: document `injectPromise` for v2
bowheart Nov 7, 2025
6dbc2af
update /not-done injectPromise links
bowheart Nov 7, 2025
5b5d326
fix pnpm-lock zedux v1 peer deps
bowheart Nov 15, 2025
4ad17cc
docs: document `injectRef` for v2
bowheart Nov 15, 2025
0dd2766
update /not-done paths for `injectRef`
bowheart Nov 15, 2025
9bdb2c3
docs: document `injectSelf` for v2
bowheart Nov 15, 2025
efbe060
some tweaks
bowheart Nov 15, 2025
ec91a3a
docs: document `injectWhy` for v2
bowheart Nov 15, 2025
767885f
docs: document the `AtomConfig` type for v2
bowheart Nov 15, 2025
6f7583b
docs: document the new `inject` util
bowheart Nov 15, 2025
eca6cc0
docs: document the new `As` util
bowheart Nov 15, 2025
50a0921
docs: document the new `getDefaultEcosystem` util for v2
bowheart Nov 15, 2025
89cd2b2
docs: document `getInternals` for v2
bowheart Nov 15, 2025
3413f6a
docs: document `is` util for v2
bowheart Nov 16, 2025
2f720fc
docs: document `setInternals` for v2
bowheart Nov 16, 2025
6d61266
docs: document new `untrack` util
bowheart Nov 16, 2025
3f36920
docs: rework selector types documentation; add some page placeholders
bowheart Nov 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: document EcosystemProvider component for v2
  • Loading branch information
bowheart committed Jul 24, 2025
commit 66a18e6f87671c8acc26cacf91fc7f128c6b6faa
8 changes: 4 additions & 4 deletions docs/docs/v2/api/classes/Ecosystem.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { createEcosystem } from '@zedux/react'
const rootEcosystem = createEcosystem({ id: 'root' })
```

Ecosystems are also created automatically when using an [`<EcosystemProvider>`](/not-done?path=../components/EcosystemProvider) without passing an `ecosystem` prop:
Ecosystems are also created automatically when using an [`<EcosystemProvider>`](../components/EcosystemProvider) without passing an `ecosystem` prop:

```tsx
import { EcosystemProvider } from '@zedux/react'
Expand All @@ -48,11 +48,11 @@ The [default ecosystem](../../../walkthrough/ecosystems#global) will be created

The default ecosystem is great for simple apps. It's a full ecosystem, which means you can use features like [overrides](#overrides) and [ecosystem events](#events). However, it comes preconfigured with no (good) way to set config options like [`ssr`](#ssr) and [`onReady`](#onready).

It's generally recommended to create your own ecosystem(s) via [`createEcosystem()`](/not-done?path=../factories/createEcosystem) and provide them to your app via [`<EcosystemProvider>`](/not-done?path=../components/EcosystemProvider) instead of using the default ecosystem. This is especially needed for SSR.
It's generally recommended to create your own ecosystem(s) via [`createEcosystem()`](/not-done?path=../factories/createEcosystem) and provide them to your app via [`<EcosystemProvider>`](../components/EcosystemProvider) instead of using the default ecosystem. This is especially needed for SSR.

## Providing

Ecosystems can take control of all atom usages in a React component tree by wrapping the tree in [`<EcosystemProvider>`](/not-done?path=../components/EcosystemProvider).
Ecosystems can take control of all atom usages in a React component tree by wrapping the tree in [`<EcosystemProvider>`](../components/EcosystemProvider).

```tsx
function App() {
Expand Down Expand Up @@ -1109,6 +1109,6 @@ ecosystem.reset({ context: { redux: otherReduxStore } }) // replaces context
- [the Plugins guide](../../../advanced/plugins)
- [`getDefaultEcosystem()`](/not-done?path=../utils/getDefaultEcosystem)
- [`setDefaultEcosystem()`](/not-done?path=../utils/setDefaultEcosystem)
- [the `<EcosystemProvider>` component](/not-done?path=../components/EcosystemProvider)
- [the `<EcosystemProvider>` component](../components/EcosystemProvider)
- [the `useEcosystem` hook](/not-done?path=../hooks/useEcosystem)
- [the `injectEcosystem` injector](/not-done?path=../injectors/injectEcosystem)
144 changes: 144 additions & 0 deletions docs/docs/v2/api/components/EcosystemProvider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
id: EcosystemProvider
title: EcosystemProvider
---

import { Legend, Item, Link, Tabs, Ts, tab1, tab2 } from '@site/src/all'

```ts
import { EcosystemProvider } from '@zedux/react'
```

A React component that provides an [ecosystem](../classes/Ecosystem) to a component tree. The provided ecosystem will take control of all atom usages below it.

You can pass either an existing [ecosystem](../classes/Ecosystem) via the `ecosystem` prop or any number of [EcosystemConfig properties](/not-done?path=../types/EcosystemConfig) via their respectively named props.

When passing config properties, the EcosystemProvider will create an ecosystem for you.

## Examples

Passing an ecosystem:

```tsx
import { EcosystemProvider, createEcosystem } from '@zedux/react'

function App() {
// this is the recommended way for most apps to create an ecosystem -
// memoized in a top-level component.
const ecosystem = useMemo(
() => createEcosystem({ id: 'root', overrides: [someAtom] }),
[]
)

return (
<EcosystemProvider ecosystem={ecosystem}>
<Routes />
</EcosystemProvider>
)
}
```

Passing configuration:

```tsx
import { EcosystemProvider } from '@zedux/react'

function App() {
return (
<EcosystemProvider id="root" overrides={[someAtom]}>
<Routes />
</EcosystemProvider>
)
}
```

All Zedux hooks in any child component will use the provided ecosystem.

Live example:

```tsx live ecosystemId=EcosystemProvider noProvide=true resultVar=App version=2
import { useEcosystem, EcosystemProvider } from '@zedux/react'

function Example() {
const ecosystem = useEcosystem()

return <div>{ecosystem.id}</div>
}

function App() {
const ecosystem = useMemo(() => createEcosystem({ id: 'root' }), [])

return (
<>
<EcosystemProvider ecosystem={ecosystem}>
<Example />
</EcosystemProvider>

<Example />
</>
)
}
```

## Signature

<Tabs>
{tab1(
`<EcosystemProvider ecosystem={ecosystem}>
{children}
</EcosystemProvider>
// or
<EcosystemProvider {...ecosystemConfig}>
{children}
</EcosystemProvider>`,
true
)}
{tab2(`declare const EcosystemProvider: ({
children,
ecosystem,
...ecosystemConfig
}:
| (Partial<{ [k in keyof EcosystemConfig]: undefined }> & {
children?: ReactNode
ecosystem?: Ecosystem
})
| (Partial<EcosystemConfig> & {
children?: ReactNode
ecosystem?: undefined
})) => React.JSX.Element`)}
</Tabs>

## Props

You must pass either an `ecosystem` prop or any combination of the ecosystem config props (no props is also fine) but not both.

<Legend>

<Item name="children">
Pass a single ReactNode child. To pass multiple components, wrap them in a React Fragment.

</Item>
<Item name="ecosystem">
An ecosystem created via [`createEcosystem()`](/not-done?path=../factories/createEcosystem).

Passing this gives you the most control over the ecosystem, at the cost of being a little lower-level.

Make sure this ecosystem reference is stable. Changing the reference is supported, but is almost never what you want as it will recreate the entire cache for all atom usages below this component.

</Item>
<Item name="ecosystemConfig">
See [the EcosystemConfig type](/not-done?path=../types/EcosystemConfig) for all the other props and their types. The EcosystemConfig key names have a one-to-one mapping with props of this component.

If the `id` prop is changed, Zedux will completely destroy the previous ecosystem and create a new one using the id and the current value of all the other EcosystemConfig props. Changing any other props besides `id` will have no effect unless `id` is also changed.

This overload is for convenience when you don't need to configure the ecosystem much. If you need more power, pass an `ecosystem` and manage it yourself.

</Item>
</Legend>

## See Also

- [The Ecosystems walkthrough](../../../walkthrough/ecosystems.mdx)
- [The `EcosystemConfig` type](/not-done?path=../types/EcosystemConfig)
- [The `Ecosystem` class](../classes/Ecosystem)
- [The `useEcosystem` hook](/not-done?path=../hooks/useEcosystem)
5 changes: 4 additions & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ module.exports = {
{
type: 'category',
label: 'Components',
items: ['v2/api/components/AtomProvider'],
items: [
'v2/api/components/AtomProvider',
'v2/api/components/EcosystemProvider',
],
},
{
type: 'category',
Expand Down