Skip to content

Instantly share code, notes, and snippets.

@DylanPiercey
Last active July 28, 2021 22:32
Show Gist options
  • Save DylanPiercey/e5edfe0ec9fb75f07267d3e7b70087e2 to your computer and use it in GitHub Desktop.
Save DylanPiercey/e5edfe0ec9fb75f07267d3e7b70087e2 to your computer and use it in GitHub Desktop.
Local storage Tags API example
<local/count=0 storageKey="count"/>
<p>You clicked ${count} times</p>
<button onClick() { count++ }>
Click me
</button>
<!-- local.marko -->
<attrs/{ default: initialValue, storageKey }/>
<const/stored=localStorage.getItem(storageKey)/>
<let/store=stored ? JSON.parse(stored) : initialValue/>
<effect() { localStorage.setItem(storageKey, JSON.stringify(store)) }/>
<return:=store/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment