Open History to see the last commit
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 }
19}