main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
575 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import { forwardRef, useEffect, useRef, } from 'react';
|
---|
| 2 | export default function useEnsuredForwardedRef(forwardedRef) {
|
---|
| 3 | var ensuredRef = useRef(forwardedRef && forwardedRef.current);
|
---|
| 4 | useEffect(function () {
|
---|
| 5 | if (!forwardedRef) {
|
---|
| 6 | return;
|
---|
| 7 | }
|
---|
| 8 | forwardedRef.current = ensuredRef.current;
|
---|
| 9 | }, [forwardedRef]);
|
---|
| 10 | return ensuredRef;
|
---|
| 11 | }
|
---|
| 12 | export function ensuredForwardRef(Component) {
|
---|
| 13 | return forwardRef(function (props, ref) {
|
---|
| 14 | var ensuredRef = useEnsuredForwardedRef(ref);
|
---|
| 15 | return Component(props, ensuredRef);
|
---|
| 16 | });
|
---|
| 17 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.