Browse guides

Share a reactive value with createPulse

Create a reactive value, update it, and notify the mounted view that reads it.

The example increments the current value and renders `Count: 1`; a separate path can rerun subscribers without changing that value.

Table of contents

Main APIs

createPulse
Creates one reactive value and returns `read()`, `write(...)` and `runSubscribers()`.
ts
import { mount } from "valyrian.js";
import { createPulse } from "valyrian.js/pulses";

const [count, setCount] = createPulse(0);

setCount((current) => current + 1);

mount("body", () => `Count: ${count()}`);

When to use runSubscribers

Use `runSubscribers()` only when you need recomputation without a value change.

API reference