Skip to content

After refreshing the page, it shows the initial value #49

@qdwang

Description

@qdwang
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>
        </>
    );
}
  1. First, let's click the Increment button for 4 times, now the foo value is displayed a number 5.
  2. Now refresh the page, the foo value will be displayed a number 1.
  3. Click the Increment button.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions