The initial data type. Defaults to a plain object.
Reactive context; defaults to the shared global context when
called without an explicit receiver. To isolate signals, bind or call with
a custom object: signal.call(myCtx, data).
The initial data. Defaults to an empty plain object.
A reactive Proxy that mirrors data, preserving array vs object shape.
// creates a reactive signal
const state = signal({
// reactive field
page: 1,
// computed reactive field
get left() {
return 100 - this.page;
},
// non-reactive methods
nextPost() {
if (this.page < 100) this.page++;
},
prevPost() {
if (this.page > 0) this.page--;
},
async fetchPost() {
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts/${this.page}`,
);
return await response.json();
},
});
Creates a reactive proxy around the given data object.
Property reads inside an active effect are automatically tracked. Writes and deletions schedule a debounced re-run of dependent effects.