TanStack

useCreateStore

Function: useCreateStore()

Call Signature

ts
function useCreateStore<T>(getValue): ReadonlyStore<T>;

Defined in: node_modules/.pnpm/@tanstack+react-store@0.11.0_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/@tanstack/react-store/dist/useCreateStore.d.ts:17

Creates a stable store instance for the lifetime of the component.

Pass an initial value to create a writable store, or a getter function to create a readonly derived store. This hook mirrors the overloads from createStore, but ensures the store is only created once per mount.

Type Parameters

T

T

Parameters

getValue

(prev?) => T

Returns

ReadonlyStore<T>

Example

tsx
const counterStore = useCreateStore({ count: 0 })

Call Signature

ts
function useCreateStore<T>(initialValue): Store<T>;

Defined in: node_modules/.pnpm/@tanstack+react-store@0.11.0_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/@tanstack/react-store/dist/useCreateStore.d.ts:18

Creates a stable store instance for the lifetime of the component.

Pass an initial value to create a writable store, or a getter function to create a readonly derived store. This hook mirrors the overloads from createStore, but ensures the store is only created once per mount.

Type Parameters

T

T

Parameters

initialValue

T

Returns

Store<T>

Example

tsx
const counterStore = useCreateStore({ count: 0 })

Call Signature

ts
function useCreateStore<T, TActions>(initialValue, actions): Store<T, TActions>;

Defined in: node_modules/.pnpm/@tanstack+react-store@0.11.0_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/@tanstack/react-store/dist/useCreateStore.d.ts:19

Creates a stable store instance for the lifetime of the component.

Pass an initial value to create a writable store, or a getter function to create a readonly derived store. This hook mirrors the overloads from createStore, but ensures the store is only created once per mount.

Type Parameters

T

T

TActions

TActions extends StoreActionMap

Parameters

initialValue

NonFunction<T>

actions

StoreActionsFactory<T, TActions>

Returns

Store<T, TActions>

Example

tsx
const counterStore = useCreateStore({ count: 0 })