Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

Subscribe.svelte

26 lines527 Bytes

1<script lang="ts">
2 import { useSelector } from '@tanstack/svelte-store'
3 import { untrack, type Snippet } from 'svelte'
4​
5 interface Props {
6 children: Snippet<[any]>
7 source: any
8 selector: (state: any) => any
9 when?: (selected: any) => boolean
10 }
11​
12 let {
13 children,
14 source,
15 selector,
16 when = () => true,
17 }: Props = $props()
18 const value = useSelector(
19 untrack(() => source),
20 untrack(() => selector),
21 )
22</script>
23​
24{#if when(value.current)}
25 {@render children(value.current)}
26{/if}