injectAtom

Function: injectAtom()

ts
function injectAtom<TValue>(atom, options?): WritableAtomSignal<TValue>;
function injectAtom<TValue>(atom, options?): WritableAtomSignal<TValue>;

Defined in: packages/angular-store/src/injectAtom.ts:44

Returns a WritableAtomSignal that reads the current atom value when called and exposes a .set method for updates.

Use this when a component needs to both read and update the same writable atom.

Type Parameters

TValue

TValue

Parameters

atom

Atom<TValue>

options?

InjectSelectorOptions<TValue>

Returns

WritableAtomSignal<TValue>

Example

ts
readonly count = injectAtom(countAtom)

increment() {
  this.count.set((prev) => prev + 1)
}
readonly count = injectAtom(countAtom)

increment() {
  this.count.set((prev) => prev + 1)
}
Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.