Skip to content

Instantly share code, notes, and snippets.

Last active June 27, 2023 20:27
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Abstraction of the local storage using Vue3's composition API
<script setup>
import useLocalStorage from './useLocalStorage'
const publicKey = useLocalStorage('solana-wallet-public-key')
<input type="text" v-model="publicKey">
<div v-text="publicKey"></div>
import { customRef } from 'vue'
export default function (key, defaultValue) {
return customRef((track, trigger) => ({
get: () => {
const value = localStorage.getItem(key)
return value ? JSON.parse(value) : defaultValue
set: value => {
if (value === null) {
} else {
localStorage.setItem(key, JSON.stringify(value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment