Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@
{
"label": "Simple",
"to": "framework/react/examples/simple"
},
{
"label": "Atoms",
"to": "framework/react/examples/atoms"
},
{
"label": "Stores",
"to": "framework/react/examples/stores"
},
{
"label": "Store Actions",
"to": "framework/react/examples/store-actions"
},
{
"label": "Store Context",
"to": "framework/react/examples/store-context"
}
]
},
Expand Down
10 changes: 2 additions & 8 deletions docs/framework/react/reference/functions/createStoreContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: createStoreContext
function createStoreContext<TValue>(): object;
```

Defined in: [react-store/src/createStoreContext.ts:40](https://github.com/TanStack/store/blob/main/packages/react-store/src/createStoreContext.ts#L40)
Defined in: [packages/react-store/src/createStoreContext.tsx:40](https://github.com/TanStack/store/blob/main/packages/react-store/src/createStoreContext.tsx#L40)

Creates a typed React context for sharing a bundle of atoms and stores with a subtree.

Expand Down Expand Up @@ -41,13 +41,7 @@ StoreProvider: (props) => ReactElement;

##### props

###### children?

`ReactNode`

###### value

`TValue`
`object` & `object`

#### Returns

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/functions/shallow.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: shallow
function shallow<T>(objA, objB): boolean;
```

Defined in: [react-store/src/shallow.ts:1](https://github.com/TanStack/store/blob/main/packages/react-store/src/shallow.ts#L1)
Defined in: [packages/react-store/src/shallow.ts:1](https://github.com/TanStack/store/blob/main/packages/react-store/src/shallow.ts#L1)

## Type Parameters

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/functions/useAtom.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: useAtom
function useAtom<TValue>(atom, options?): [TValue, (fn) => void & (value) => void];
```

Defined in: [react-store/src/useAtom.ts:17](https://github.com/TanStack/store/blob/main/packages/react-store/src/useAtom.ts#L17)
Defined in: [packages/react-store/src/useAtom.ts:17](https://github.com/TanStack/store/blob/main/packages/react-store/src/useAtom.ts#L17)

Returns the current atom value together with a stable setter.

Expand Down
4 changes: 2 additions & 2 deletions docs/framework/react/reference/functions/useCreateAtom.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: useCreateAtom
function useCreateAtom<T>(getValue, options?): ReadonlyAtom<T>;
```

Defined in: [react-store/src/useCreateAtom.ts:17](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateAtom.ts#L17)
Defined in: [packages/react-store/src/useCreateAtom.ts:17](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateAtom.ts#L17)

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

Expand Down Expand Up @@ -51,7 +51,7 @@ const countAtom = useCreateAtom(0)
function useCreateAtom<T>(initialValue, options?): Atom<T>;
```

Defined in: [react-store/src/useCreateAtom.ts:21](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateAtom.ts#L21)
Defined in: [packages/react-store/src/useCreateAtom.ts:21](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateAtom.ts#L21)

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

Expand Down
48 changes: 46 additions & 2 deletions docs/framework/react/reference/functions/useCreateStore.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: useCreateStore
function useCreateStore<T>(getValue): ReadonlyStore<T>;
```

Defined in: [react-store/src/useCreateStore.ts:17](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateStore.ts#L17)
Defined in: [packages/react-store/src/useCreateStore.ts:24](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateStore.ts#L24)

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

Expand Down Expand Up @@ -47,7 +47,7 @@ const counterStore = useCreateStore({ count: 0 })
function useCreateStore<T>(initialValue): Store<T>;
```

Defined in: [react-store/src/useCreateStore.ts:20](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateStore.ts#L20)
Defined in: [packages/react-store/src/useCreateStore.ts:27](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateStore.ts#L27)

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

Expand Down Expand Up @@ -76,3 +76,47 @@ createStore, but ensures the store is only created once per mount.
```tsx
const counterStore = useCreateStore({ count: 0 })
```

## Call Signature

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

Defined in: [packages/react-store/src/useCreateStore.ts:28](https://github.com/TanStack/store/blob/main/packages/react-store/src/useCreateStore.ts#L28)

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 })
```
2 changes: 1 addition & 1 deletion docs/framework/react/reference/functions/useSelector.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function useSelector<TSource, TSelected>(
options?): TSelected;
```

Defined in: [react-store/src/useSelector.ts:41](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSelector.ts#L41)
Defined in: [packages/react-store/src/useSelector.ts:41](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSelector.ts#L41)

Selects a slice of state from an atom or store and subscribes the component
to that selection.
Expand Down
12 changes: 8 additions & 4 deletions docs/framework/react/reference/functions/useSetValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: useSetValue
function useSetValue<TValue>(source): (fn) => void & (value) => void;
```

Defined in: [react-store/src/useSetValue.ts:23](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSetValue.ts#L23)
Defined in: [packages/react-store/src/useSetValue.ts:23](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSetValue.ts#L23)

Returns a stable setter for a writable atom or store.

Expand Down Expand Up @@ -50,10 +50,10 @@ setState((prev) => ({ ...prev, count: prev.count + 1 }))
## Call Signature

```ts
function useSetValue<TValue>(source): (updater) => void;
function useSetValue<TValue, TActions>(source): (updater) => void;
```

Defined in: [react-store/src/useSetValue.ts:24](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSetValue.ts#L24)
Defined in: [packages/react-store/src/useSetValue.ts:24](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSetValue.ts#L24)

Returns a stable setter for a writable atom or store.

Expand All @@ -67,11 +67,15 @@ values and updater functions. Writable stores preserve their native

`TValue`

#### TActions

`TActions` *extends* `StoreActionMap`

### Parameters

#### source

`Store`\<`TValue`\>
`Store`\<`TValue`, `TActions`\>

### Returns

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/functions/useStore.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function useStore<TSource, TSelected>(
compare?): TSelected;
```

Defined in: [react-store/src/useStore.ts:8](https://github.com/TanStack/store/blob/main/packages/react-store/src/useStore.ts#L8)
Defined in: [packages/react-store/src/useStore.ts:8](https://github.com/TanStack/store/blob/main/packages/react-store/src/useStore.ts#L8)

Deprecated alias for [useSelector](useSelector.md).

Expand Down
44 changes: 44 additions & 0 deletions docs/framework/react/reference/functions/useStoreActions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
id: useStoreActions
title: useStoreActions
---

# Function: useStoreActions()

```ts
function useStoreActions<TValue, TActions>(store): TActions;
```

Defined in: [packages/react-store/src/useStoreActions.ts:16](https://github.com/TanStack/store/blob/main/packages/react-store/src/useStoreActions.ts#L16)

Returns the stable actions bag from a writable store created with actions.

Use this when a component only needs to call store actions and should not
subscribe to state changes.

## Type Parameters

### TValue

`TValue`

### TActions

`TActions` *extends* `StoreActionMap`

## Parameters

### store

`Store`\<`TValue`, `TActions`\>

## Returns

`TActions`

## Example

```tsx
const actions = useStoreActions(counterStore)
actions.inc()
```
4 changes: 2 additions & 2 deletions docs/framework/react/reference/functions/useValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: useValue
function useValue<TValue>(source, options?): TValue;
```

Defined in: [react-store/src/useValue.ts:23](https://github.com/TanStack/store/blob/main/packages/react-store/src/useValue.ts#L23)
Defined in: [packages/react-store/src/useValue.ts:23](https://github.com/TanStack/store/blob/main/packages/react-store/src/useValue.ts#L23)

Subscribes to an atom or store and returns its current value.

Expand All @@ -28,7 +28,7 @@ should be treated as equivalent.

### source

`Atom`\<`TValue`\> | `ReadonlyAtom`\<`TValue`\> | `Store`\<`TValue`\> | `ReadonlyStore`\<`TValue`\>
`Atom`\<`TValue`\> | `ReadonlyAtom`\<`TValue`\> | `Store`\<`TValue`, `any`\> | `ReadonlyStore`\<`TValue`\>

### options?

Expand Down
1 change: 1 addition & 0 deletions docs/framework/react/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ title: "@tanstack/react-store"
- [useSelector](functions/useSelector.md)
- [useSetValue](functions/useSetValue.md)
- [~~useStore~~](functions/useStore.md)
- [useStoreActions](functions/useStoreActions.md)
- [useValue](functions/useValue.md)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: UseSelectorOptions

# Interface: UseSelectorOptions\<TSelected\>

Defined in: [react-store/src/useSelector.ts:4](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSelector.ts#L4)
Defined in: [packages/react-store/src/useSelector.ts:4](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSelector.ts#L4)

## Type Parameters

Expand All @@ -21,7 +21,7 @@ Defined in: [react-store/src/useSelector.ts:4](https://github.com/TanStack/store
optional compare: (a, b) => boolean;
```

Defined in: [react-store/src/useSelector.ts:5](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSelector.ts#L5)
Defined in: [packages/react-store/src/useSelector.ts:5](https://github.com/TanStack/store/blob/main/packages/react-store/src/useSelector.ts#L5)

#### Parameters

Expand Down
14 changes: 7 additions & 7 deletions docs/reference/classes/ReadonlyStore.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: ReadonlyStore

# Class: ReadonlyStore\<T\>

Defined in: [store.ts:31](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L31)
Defined in: [store.ts:61](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L61)

## Type Parameters

Expand All @@ -15,7 +15,7 @@ Defined in: [store.ts:31](https://github.com/TanStack/store/blob/main/packages/s

## Implements

- `Omit`\<[`Store`](Store.md)\<`T`\>, `"setState"`\>
- `Omit`\<[`Store`](Store.md)\<`T`\>, `"setState"` \| `"actions"`\>

## Constructors

Expand All @@ -25,7 +25,7 @@ Defined in: [store.ts:31](https://github.com/TanStack/store/blob/main/packages/s
new ReadonlyStore<T>(getValue): ReadonlyStore<T>;
```

Defined in: [store.ts:33](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L33)
Defined in: [store.ts:66](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L66)

#### Parameters

Expand All @@ -43,7 +43,7 @@ Defined in: [store.ts:33](https://github.com/TanStack/store/blob/main/packages/s
new ReadonlyStore<T>(initialValue): ReadonlyStore<T>;
```

Defined in: [store.ts:34](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L34)
Defined in: [store.ts:67](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L67)

#### Parameters

Expand All @@ -65,7 +65,7 @@ Defined in: [store.ts:34](https://github.com/TanStack/store/blob/main/packages/s
get state(): T;
```

Defined in: [store.ts:42](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L42)
Defined in: [store.ts:75](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L75)

##### Returns

Expand All @@ -85,7 +85,7 @@ Omit.state
get(): T;
```

Defined in: [store.ts:45](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L45)
Defined in: [store.ts:78](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L78)

#### Returns

Expand All @@ -105,7 +105,7 @@ Omit.get
subscribe(observerOrFn): Subscription;
```

Defined in: [store.ts:48](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L48)
Defined in: [store.ts:81](https://github.com/TanStack/store/blob/main/packages/store/src/store.ts#L81)

#### Parameters

Expand Down
Loading
Loading