Skip to content

Commit

Permalink
[utils] Add documentation to useForkRef (#44410)
Browse files Browse the repository at this point in the history
  • Loading branch information
JCQuintas authored Nov 15, 2024
1 parent 81337b2 commit 2224b22
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/mui-utils/src/useForkRef/useForkRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
import * as React from 'react';
import setRef from '../setRef';

/**
* Takes an array of refs and returns a new ref which will apply any modification to all of the refs.
*
* This is useful when you want have the ref used in multiple places.
*
* ```tsx
* const newRef = React.useRef<Instance>(null);
* const refFork = useForkRef(newRef, props.ref);
*
* return (
* <LogicProvider ref={newRef}>
* <Component ref={refFork} />
* </LogicProvider>
* );
* ```
*
* @param {Array<React.Ref<Instance> | undefined>} refs the ref array.
* @returns {React.RefCallback<Instance> | null} the new ref callback.
*/
export default function useForkRef<Instance>(
...refs: Array<React.Ref<Instance> | undefined>
): React.RefCallback<Instance> | null {
Expand Down

0 comments on commit 2224b22

Please sign in to comment.