[]previous and next page

refTo

Fills a ref of any form the compiler accepts.

Fills a ref of any form the compiler accepts. A callback is called with the element (its returned cleanup runs when the owner disposes). A { current } object gets the element as current, and null once the owner is disposed, as React's useRef objects do. Any other value is ignored.

Import#

ts
import { refTo } from "@shadow-js/web";

Signature#

ts
function refTo(target: unknown, el: Element): void

Parameters#

Name Description
target The ref value: a callback, a { current } object, or anything else (ignored).
el The element the ref receives.

Examples#

ts
import { refTo } from "@shadow-js/web";

const box = { current: null as HTMLDivElement | null };
const div = document.createElement("div");
refTo(box, div);
console.log(box.current === div); // true