# Advanced: Using Page State

{% hint style="info" %}
Page State has been superseded by Mod Variables for working with mod-scoped data. Mod Variables are easy to reference via `@mod` , and enable PixieBrix to apply automatic performance optimizations
{% endhint %}

Page State is in-memory storage that’s available during a page session. There are three Page State namespaces to isolate information:

* Private — visible only for bricks in the mod component
* Mod — visible to all mod components in the mod
* Public — visible to all mods

There are two bricks to write/read directly from Page State:

* [Set shared page state](https://www.pixiebrix.com/marketplace/cb54eca2-d3b2-456c-9b6a-a35c031420c6/)
* [Get shared page state](https://www.pixiebrix.com/marketplace/7073cbed-6ee5-4252-92a3-b93f4dfffc5f/)

Additionally, there are other bricks that can connect to the Page State

* Trigger Starter Brick: can listen for changes to Page State
* Sidebar Starter Brick: can re-render on changes to Page State
* Custom Form: can be synchronized to Mod Variables/Page State
* Display Temporary Information: can re-render on changes to Page State
* With Async Async Page State: runs one or more bricks asynchronously and keeps track of the result in a Mod Variable

### Getting Page State

The “Get Shared Page State” brick retrieves all data for the chosen namespace and assigns it to a Local Variable.

Using “Get Shared Page State” can be useful to take a snapshot of multiple Mod Variables at a single point in time.

### Setting Page State

The “Set Shared Page State” brick provides full control over how to update Page State, including Mod Variables stored in the mod namespace.

#### Merge Strategy

The Merge Strategy input of the “Set shared page state” brick controls how the values provided impact existing values:

* Shallow (default): properties provided overwrite existing properties. Other properties are preserved
* Replace: replace the page state with the new values
* Deep: merge properties, including nested objects. For arrays, items are merged pairwise. If two values are different types, the value is replaced

#### Example: Replace State

Before:

```yaml
hasRun: false
message: "Some text"
```

Update

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

After

```yaml
# The message field is removed, because the whole state is replaced
hasRun: true
```

#### Example: Shallow Merge

Before

```yaml
hasRun: false
message: "Some text"
```

Update

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

After

```yaml
hasRun: true
# The `message` key is not modified
message: "Some text"
```

#### Example: Deep Merge

{% hint style="info" %}
In “deep” merge mode, arrays items are merged together pair-wise. (They are not appended)
{% endhint %}

Before: State

```yaml
hasRun: false
exampleObject:
  key1: "Text value"  
```

Before: `@data`

```yaml
exampleObject:
  key2: "Key from @data object"
```

Update

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

After

```yaml
hasRun: false
exampleObject:
  key1: "Text value"
  # key2 is deep merged into exampleObject
  key2: "Key from @data object"
```


---

# 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.pixiebrix.com/developing-mods/developer-concepts/variables-and-data-context/advanced-using-page-state.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.
