# Save to Local Storage

With the Save to Local Storage action, you can save values in the browser's local storage. \
This is useful when you want to share the same value between multiple pages, like user token or user preferences. The saved value is available as `{{localStorage.<key>}}` in all actions and components.

To configure the action, you need to specify your variable's name as this name will be used to access the value in the local storage. Then, you need to pass the data you want to save in the *New value* field.

<figure><img src="/files/QoTPipm0rlM0sexYyzbi" alt=""><figcaption></figcaption></figure>

## Examples

### Saving the result of the previous step

```javascript
{{data.token}}
```

You can always adjust the data before saving it.

### Adding additional values

```javascript
const values = {{ui.form.value}};

return {
  ...values,
  created_at: new Date(),
}Jav
```

{% hint style="warning" %}
The `created_at` column must exist in the table schema, otherwise it won't be sent.
{% endhint %}

### Changing values

```javascript
const values = {{ui.form.value}};
return {
  ...values,
  name: values.name.toUpperCase(),
}
```

### Deleting unwanted values

```javascript
const values = {{ui.form.value}};
delete values.age;
return values;
```

alternatively:

```javascript
const values = {{ui.form.value}};
const { created_at, ...rest } = values;
return rest;
```

### Joining array values

```javascript
const values = {{ui.form.value}};
return {
  ...values,
  tags: values.tags.join(','),
}
```

### Using default values

```javascript
const values = {{ui.form.value}};
return {
  ...values,
  // if the value is not set, use the default value
  created_at: values.created_at || new Date(),
}
```

***

More information on `localStorage` you can find here :point\_down:

{% content-ref url="/pages/nWfBvM56sZ1L9ATrFdVl" %}
[Local storage](/concepts/localstorage.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uibakery.io/reference/working-with-actions/save-to-local-storage-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
