Created
August 15, 2025 21:45
-
-
Save tijnjh/09077fa014fc6bb26148ca2bd94a5553 to your computer and use it in GitHub Desktop.
svelte ref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Ref<T> { | |
get current(): T | |
set current(value: T) | |
} | |
export function ref<T>(value: T): Ref<T> { | |
let state = $state<T>(value) | |
return { | |
get current() { | |
return state | |
}, | |
set current(value: T) { | |
state = value | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment