import { persistentAtom } from '@nanostores/persistent';
import { useStore } from '@nanostores/solid';
export const $foo = persistentAtom('foo', 1, {
encode(x) {
return x + ''
},
decode(x) {
return parseInt(x)
}
})
export const setFoo = x => {
$foo.set(x)
}
export default function () {
const foo = useStore($foo);
return (
<>
<div>Foo: {foo()}</div>
<button class="button is-small" onClick={() => setFoo(foo() + 1)}>Increment foo</button>
</>
);
}
- First, let's click the Increment button for 4 times, now the foo value is displayed a number 5.
- Now refresh the page, the foo value will be displayed a number 1.
- Click the Increment button.
- The foo value displays a number 6.
The second step is wrong, after refreshing the page, it should display a number 5.
Don't know if I was using it correctly.
The second step is wrong, after refreshing the page, it should display a number 5.
Don't know if I was using it correctly.