Skip to content
Merged
Changes from 2 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
19 changes: 19 additions & 0 deletions docs/docs/with-resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ With named resources, each resource gets prefixed properties:
- **Single resource:** use when your store works with just one data source.
- **Named resources:** use when your store is larger and manages multiple entities or async operations.

## Updating

The state to patch corresponds directly to the name of the resource's value signal.

```ts
const UserStore = signalStore(
withResource((state) => httpResource<User>(() => `/user/${state.userId}`)),
withResource(({ userId }) => ({
list: httpResource<User[]>(() => '/users', { defaultValue: [] }),
})),
);

// Unnamed resource: `value`
patchState(store, { value: { id: 1, name: 'John' } });

// Named resource: name prefix + `Value`
patchState(store, ({ listValue }) => ({ listValue: [...(listValue ?? []), { id: 1, name: 'John' }] }));
```

## Error Handling

The error throwing behavior of the native `resource` causes a deadlock in the error case.
Expand Down