-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import useEnsuredForwardedRef as standalone
This commit removes the need to import `react-use` package as dependency, which reduces the bundle size in 0.5MB (npm reports). Since the only function that is used is `useEnsuredForwardedRef` it was imported directly as a standalone js file into `src/hooks` directory. Closes #152
- Loading branch information
1 parent
706699c
commit ce3a13b
Showing
4 changed files
with
1,566 additions
and
1,820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
useEffect, | ||
useRef, | ||
} from 'react'; | ||
|
||
export function useEnsuredForwardedRef( | ||
forwardedRef | ||
) { | ||
const ensuredRef = useRef(forwardedRef && forwardedRef.current); | ||
|
||
useEffect(() => { | ||
if (!forwardedRef) { | ||
return; | ||
} | ||
forwardedRef.current = ensuredRef.current; | ||
}, [forwardedRef]); | ||
|
||
return ensuredRef; | ||
} |
Oops, something went wrong.