Skip to content

Commit

Permalink
Merge pull request #153 from lightningspirit/deps/remove-react-use-deps
Browse files Browse the repository at this point in the history
Import useEnsuredForwardedRef as standalone
  • Loading branch information
Wildhoney committed Jun 12, 2023
2 parents 7a7a810 + ce3a13b commit 47b29a1
Show file tree
Hide file tree
Showing 4 changed files with 1,566 additions and 1,820 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"humps": "^2.0.1",
"react-use": "^17.0.0"
"humps": "^2.0.1"
},
"devDependencies": {
"@babel/core": "^7.11.1",
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useLayoutEffect, forwardRef } from 'react';
import { useEnsuredForwardedRef } from 'react-use';
import { useEnsuredForwardedRef } from '../hooks';
import { createPortal } from 'react-dom';
import { renderToString } from 'react-dom/server';
import PropTypes from 'prop-types';
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/index.js
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;
}
Loading

0 comments on commit 47b29a1

Please sign in to comment.