chainRefs function

dynamic chainRefs(
  1. dynamic ref1,
  2. dynamic ref2
)

Returns a ref that updates both ref1 and ref2, effectively allowing you to set multiple refs.

Useful when you're using ref forwarding and want to also set your own ref.

For more information on this problem, see https://github.com/facebook/react/issues/13029.

Inputs can be callback refs, createRef-based refs (Ref), or raw JS createRef refs (JsRef).

If either ref1 or ref2 is null, the other ref will be passed through.

If both are null, null is returned.

final Example = forwardRef((props, ref) {
  final localRef = useRef<FooComponent>();
  return Foo({
    ...props,
    'ref': chainRefs(localRef, ref),
  });
});

Implementation

dynamic chainRefs(dynamic ref1, dynamic ref2) {
  return chainRefList([ref1, ref2]);
}