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

utils.svelte.ts

19 lines453 Bytes

1type Box<T> = { current: T }
2​
3/**
4 * Creates a reactive box: an object whose `current` property is backed by `$state`.
5 * @param initial - The initial value of `current`.
6 * @returns An object whose `current` property reads and writes the state.
7 */
8export function box<T>(initial: T): Box<T> {
9 let current = $state(initial)
10​
11 return {
12 get current() {
13 return current
14 },
15 set current(newValue) {
16 current = newValue
17 },
18 }