Function: bindText

vanilla.bindText

bindText(element, getter): () => void

Directly synchronizes an HTML element's textContent with a reactive getter function.

Parameters

Name Type Description
element HTMLElement The HTML element whose text content will be updated.
getter () => string | number Pure function returning the reactive string or number to render.

Returns

fn

A dispose function to unbind the reactive text synchronization.

(): void

Returns

void

Example

import { bindText, signal } from '@banksia/signals/vanilla';

const count = signal(0);
const span = document.querySelector('#counter-display') as HTMLElement;

const unbind = bindText(span, () => `Count: ${count.value}`);
count.value = 5; // span.textContent updates to 'Count: 5'
ON THIS PAGE