--- url: /reference/items/DataBind.md --- # DataBind Use the `DataBind` to create a one-way binding of a property of the targeted DOM element. This component should be used with the [`DataModel` component](../DataModel/index.md), which handles two-way bindings. The related [`DataComputed`](../DataComputed/index.md) and [`DataEffect`](../DataEffect/index.md) components can also be used for computed values and side effects respectively. ## Usage Import the components in your main app and use the [`DataModel` component](../DataModel/index.md) on HTML `
` elements and the `DataBind` and [`DataComputed`](../DataComputed/index.md) components on other elements that need to be updated accordingly. The [`DataEffect` component](../DataEffect/index.md) can be used to execute side effects when the value changes. ### Basic usage ::: code-group ```js [app.js] twoslash import { registerComponents } from '@studiometa/js-toolkit'; import { Action, DataBind, DataModel, DataScope } from '@studiometa/ui'; registerComponents(Action, DataScope, DataBind, DataModel); ``` ```html [index.html]
Hello world
``` ::: ### Multiple virtual bindings Use virtual `data-bind:*` attributes to update several parts of an element — its class, ARIA state, and content — from one value, without a JavaScript class. See the [virtual bindings reference](./js-api.md#virtual-bindings) for the full syntax. The following disclosure keeps its button label while updating its class, ARIA state, and panel visibility from one scoped value. The `DataModel` uses its `value` property to hydrate the initial state; virtual bindings then retain the reactive value without replacing the label. ```html
``` ### Conditional rendering Use the `data-bind:if` binding on a `