# globalAtomFamily

Signature
`globalAtomFamily<T, K>(defaultFactory: (key: K) => T, options: GlobalAtomFamilyOptions): GlobalAtomFamily<T, K>`

valdres
Creates a keyed collection of cross-store singleton atoms

Combines [`atomFamily`](https://valdres.dev/valdres/atomFamily) and [`globalAtom`](https://valdres.dev/valdres/globalAtom):
each member is keyed by a parameter, and each member's value is shared across
every store that touches it.

`options.name` is required — it is the family's global address. Re-defining a
family under the same name returns the existing family instead of creating a
second one, so calling `globalAtomFamily` again with the same name is safe
(and idempotent) wherever it happens.

## Usage

```ts
import { globalAtomFamily } from "valdres"

const featureFlagAtom = globalAtomFamily((key: string) => false, {
    name: "app/feature-flags",
})

featureFlagAtom("dark-mode").setSelf(true)
```

Same call shape as [`atomFamily`](https://valdres.dev/valdres/atomFamily) — the only difference
is that `options.name` is required instead of optional.

Each member carries the same `getSelf` / `setSelf` / `resetSelf` accessors as
a plain [`globalAtom`](https://valdres.dev/valdres/globalAtom#the-self-accessors):

```ts
const flag = featureFlagAtom("dark-mode")
flag.getSelf()   // read without a Store handle
flag.setSelf(true)
```

## Parameters

`globalAtomFamily` accepts the same options as
[`atomFamily`](https://valdres.dev/valdres/atomFamily) (`keyOf`, plus every `AtomOptions` field)
as `GlobalAtomFamilyOptions` — identical to `AtomFamilyOptions`, except `name`
is required instead of optional.

## See also

- [globalAtom](https://valdres.dev/valdres/globalAtom) — a single cross-store atom
- [atomFamily](https://valdres.dev/valdres/atomFamily) — a per-store keyed collection of atoms
