Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Polish useForkRef docs #44424

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions packages/mui-utils/src/useForkRef/useForkRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ 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.
* This is useful when you want to have the ref used in multiple places.
*
* ```tsx
* const newRef = React.useRef<Instance>(null);
* const refFork = useForkRef(newRef, props.ref);
* const rootRef = React.useRef<Instance>(null);
* const refFork = useForkRef(rootRef, props.ref);
*
* return (
* <LogicProvider ref={newRef}>
* <Component ref={refFork} />
* </LogicProvider>
* <Root {...props} ref={refFork} />
* );
* ```
*
* @param {Array<React.Ref<Instance> | undefined>} refs the ref array.
* @returns {React.RefCallback<Instance> | null} the new ref callback.
* @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>
Expand Down