@motion-script/core / RefTarget
Type Alias: RefTarget()<T>
RefTarget<
T> =void
Defined in: util/reference.ts:45
A slot that can receive a T — a Reference<T>, or one declared as any
supertype of T.
This is the type a node's ref prop takes, and the widening is deliberate:
the framework only ever writes into a ref (props.ref(this) in the Node
constructor) and the author only ever reads, so handing a Rect to a
Reference<ShapeNode> is sound in both directions — the write stores a
subtype, the read yields the supertype the author asked for. That is what
lets one ref hold whichever shape a factory happened to build:
const ref = createRef<ShapeNode>();
<Rect ref={ref} /> // ✔ Rect is a ShapeNode
<Ellipse ref={ref} /> // ✔ so is Ellipse
The opposite direction stays an error, because it is the unsound one: a
Reference<Rect> on a <Text> would be handed a Text at runtime while
still typing every read as a Rect.
A plain setter function is accepted too, which makes React-style callback
refs (ref={n => …}) work without a separate type.
Type Parameters
T
T
RefTarget(
node):void
A slot that can receive a T — a Reference<T>, or one declared as any
supertype of T.
This is the type a node's ref prop takes, and the widening is deliberate:
the framework only ever writes into a ref (props.ref(this) in the Node
constructor) and the author only ever reads, so handing a Rect to a
Reference<ShapeNode> is sound in both directions — the write stores a
subtype, the read yields the supertype the author asked for. That is what
lets one ref hold whichever shape a factory happened to build:
const ref = createRef<ShapeNode>();
<Rect ref={ref} /> // ✔ Rect is a ShapeNode
<Ellipse ref={ref} /> // ✔ so is Ellipse
The opposite direction stays an error, because it is the unsound one: a
Reference<Rect> on a <Text> would be handed a Text at runtime while
still typing every read as a Rect.
A plain setter function is accepted too, which makes React-style callback
refs (ref={n => …}) work without a separate type.
Parameters
node
T | null
Returns
void
Properties
__accepts?
readonlyoptional__accepts?: (node) =>void
Defined in: util/reference.ts:47
Parameters
node
T
Returns
void