Skip to content

Commit 7b791d1

Browse files
committed
bring back a hook to build markdown editor
1 parent cf9c66a commit 7b791d1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export {useProvidedStateOrCreate} from './useProvidedStateOrCreate'
1313
export {useMenuInitialFocus} from './useMenuInitialFocus'
1414
export {useMenuKeyboardNavigation} from './useMenuKeyboardNavigation'
1515
export {useMnemonics} from './useMnemonics'
16+
export {useRefObjectAsForwardedRef} from './useRefObjectAsForwardedRef'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {ForwardedRef, RefObject, useImperativeHandle} from 'react'
2+
3+
/**
4+
* Use a ref object as the imperative handle for a forwarded ref. This can be used to
5+
* synchronize the ref object with the forwarded ref and allow local access the reference
6+
* instance with `.current`.
7+
*
8+
* **NOTE**: The `refObject` should be passed to the underlying element, NOT the `forwardedRef`.
9+
*/
10+
export function useRefObjectAsForwardedRef<T>(forwardedRef: ForwardedRef<T>, refObject: RefObject<T>): void {
11+
useImperativeHandle<T | null, T | null>(forwardedRef, () => refObject.current)
12+
}

0 commit comments

Comments
 (0)