# Query String

Synchronize component data properties with URL query parameters to create shareable, bookmarkable URLs that reflect your component's state. When users modify data properties, the URL automatically updates, and when they visit URLs with query parameters, your component initializes with those values.

## Basic Usage

Create a search component that updates the URL as users type:

{% tabs %}
{% tab title="BoxLang" %}

```javascript
// wires/ArticleSearch.bx
class extends="cbwire.models.Component" {
    data = {
        "search": "",
        "category": "",
        "results": []
    };
    
    queryString = ["search", "category"];
    
    function onMount() {
        performSearch();
    }
    
    function onUpdate() {
        performSearch();
    }
    
    function performSearch() {
        if (data.search.len() > 2) {
            // Simulate search results
            data.results = [
                {"title": "Article 1", "category": "Tech"},
                {"title": "Article 2", "category": "News"}
            ];
        } else {
            data.results = [];
        }
    }
}
```

{% endtab %}

{% tab title="CFML" %}

```javascript
// wires/ArticleSearch.cfc
component extends="cbwire.models.Component" {
    data = {
        "search" = "",
        "category" = "",
        "results" = []
    };
    
    queryString = ["search", "category"];
    
    function onMount() {
        performSearch();
    }
    
    function onUpdate() {
        performSearch();
    }
    
    function performSearch() {
        if (len(data.search) > 2) {
            // Simulate search results
            data.results = [
                {"title" = "Article 1", "category" = "Tech"},
                {"title" = "Article 2", "category" = "News"}
            ];
        } else {
            data.results = [];
        }
    }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="BoxLang" %}

```html
<!-- wires/articleSearch.bxm -->
<bx:output>
<div>
    <h1>Article Search</h1>
    
    <div class="search-form">
        <input wire:model="search" 
               type="search" 
               placeholder="Search articles...">
        
        <select wire:model="category">
            <option value="">All Categories</option>
            <option value="tech">Technology</option>
            <option value="news">News</option>
            <option value="sports">Sports</option>
        </select>
    </div>
    
    <div class="results">
        <h2>Results (#results.len()#)</h2>
        <bx:loop array="#results#" item="article">
            <div class="article">
                <h3>#article.title#</h3>
                <span class="category">#article.category#</span>
            </div>
        </bx:loop>
    </div>
</div>
</bx:output>
```

{% endtab %}

{% tab title="CFML" %}

```html
<!-- wires/articleSearch.cfm -->
<cfoutput>
<div>
    <h1>Article Search</h1>
    
    <div class="search-form">
        <input wire:model="search" 
               type="search" 
               placeholder="Search articles...">
        
        <select wire:model="category">
            <option value="">All Categories</option>
            <option value="tech">Technology</option>
            <option value="news">News</option>
            <option value="sports">Sports</option>
        </select>
    </div>
    
    <div class="results">
        <h2>Results (#arrayLen(results)#)</h2>
        <cfloop array="#results#" item="article">
            <div class="article">
                <h3>#article.title#</h3>
                <span class="category">#article.category#</span>
            </div>
        </cfloop>
    </div>
</div>
</cfoutput>
```

{% endtab %}
{% endtabs %}

When users visit `/articles?search=javascript&category=tech`, the component automatically initializes with those values and performs the search.

{% hint style="info" %}
Query string synchronization happens automatically when data properties change. You don't need to manually update the URL.
{% endhint %}

{% hint style="warning" %}
Only properties listed in the `queryString` array will be synchronized with the URL. Other data properties remain internal to the component.
{% endhint %}


---

# 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://cbwire.ortusbooks.com/features/query-string.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.
