[]previous and next page

createRef

Creates a Ref.

Creates a Ref. Calling it with a value stores the value; calling it with undefined clears it. The same object works as a plain ref callback, so no forwardRef is needed.

Import#

ts
import { createRef } from "@shadow-js/core";

Signature#

ts
function createRef<T>(): Ref<T>

Returns#

A callable ref with a current getter, undefined until the ref is called.

Examples#

ts
import { createRef } from "@shadow-js/core";

function SearchBox() {
  const input = createRef<HTMLInputElement>();
  return <input ref={input} onKeyDown={() => input.current?.select()} />;
}