-
Notifications
You must be signed in to change notification settings - Fork 0
@bynary.composables.ngxs.Function.useSelect
@bynary/composables / @bynary/composables/ngxs / useSelect
Selects a slice of data from an Store NGXS store. Uses Store#select internally and converts its observable to a signal.
@Component({
template: `
My books:
<ul>
<li *ngFor="let book of books()>{{ book }}</li>
</ul>
`
})
class BooksComponent {
// legacy way using an Observable
@Select(BooksState.books)
books$: Observable<string[]>;
// new way using a signal
books = useSelect(BooksState.books);
}
The selector function or key
useSelect<
T
>(selector
):Signal
<T
>
Selects a slice of data from an Store NGXS store. Uses Store#select internally and converts its observable to a signal.
• T
• selector
Signal
<T
>
@Component({
template: `
My books:
<ul>
<li *ngFor="let book of books()>{{ book }}</li>
</ul>
`
})
class BooksComponent {
// legacy way using an Observable
@Select(BooksState.books)
books$: Observable<string[]>;
// new way using a signal
books = useSelect(BooksState.books);
}
The selector function or key
ngxs/src/select.composable.ts:7
useSelect<
T
>(selector
):Signal
<T
>
Selects a slice of data from an Store NGXS store. Uses Store#select internally and converts its observable to a signal.
• T = any
• selector: string
| Type
<any
>
Signal
<T
>
@Component({
template: `
My books:
<ul>
<li *ngFor="let book of books()>{{ book }}</li>
</ul>
`
})
class BooksComponent {
// legacy way using an Observable
@Select(BooksState.books)
books$: Observable<string[]>;
// new way using a signal
books = useSelect(BooksState.books);
}
The selector function or key
ngxs/src/select.composable.ts:8
useSelect<
T
>(selector
):Signal
<T
>
Selects a slice of data from an Store NGXS store. Uses Store#select internally and converts its observable to a signal.
• T
• selector: StateToken
<T
>
Signal
<T
>
@Component({
template: `
My books:
<ul>
<li *ngFor="let book of books()>{{ book }}</li>
</ul>
`
})
class BooksComponent {
// legacy way using an Observable
@Select(BooksState.books)
books$: Observable<string[]>;
// new way using a signal
books = useSelect(BooksState.books);
}
The selector function or key