Skip to content

Is there an easy solution for persisting input values? #887

Answered by Fil
gouldingken asked this question in Q&A
Discussion options

You must be logged in to vote

Yes I think you could use localStorage to save state (or sessionStorage if you want two browser windows to have their own separate history, which I tend to prefer); then set the initial value of fresh Inputs to the stored value, if any.

It could go like this (in two different js code blocks):

```js
const defaultColor = "#ff0000";
const color = view(Inputs.color({value: sessionStorage.getItem("color") ?? defaultColor}));
```

```js
{
  sessionStorage.setItem("color", color);
}
```

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mbostock
Comment options

Answer selected by gouldingken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants