Skip to content

Instantly share code, notes, and snippets.

@tijnjh
Created August 15, 2025 21:45
Show Gist options
  • Save tijnjh/09077fa014fc6bb26148ca2bd94a5553 to your computer and use it in GitHub Desktop.
Save tijnjh/09077fa014fc6bb26148ca2bd94a5553 to your computer and use it in GitHub Desktop.
svelte ref
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