Back to articles
Nanostores Has a Free API That Most Developers Don't Know About

Nanostores Has a Free API That Most Developers Don't Know About

via Dev.to ReactAlex Spinov

Nanostores is a tiny (286 bytes) state management library that works with React, Vue, Svelte, Angular, and vanilla JS. Perfect for framework-agnostic shared state. Basic Atoms import { atom , computed } from " nanostores " ; export const $count = atom ( 0 ); export const $double = computed ( $count , c => c * 2 ); // Update from anywhere $count . set ( 5 ); $count . set ( $count . get () + 1 ); React Integration import { useStore } from " @nanostores/react " ; import { $count , $double } from " ./stores " ; function Counter () { const count = useStore ( $count ); const double = useStore ( $double ); return < button onClick = {() => $count . set ( count + 1 )} > { count } ({ double }) < /button> ; } Vue Integration < script setup > import { useStore } from " @nanostores/vue " ; import { $count } from " ./stores " ; const count = useStore ( $count ); </ script > < template ><button @ click= "$count.set(count + 1)" > {{ count }} </button></ template > Map Store (Objects) import { map } fr

Continue reading on Dev.to React

Opens in a new tab

Read Full Article
7 views

Related Articles