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

Use useEffect for SSR, add ref.current to dependency array #139

Merged
merged 1 commit into from
Feb 16, 2021

Conversation

whplh
Copy link

@whplh whplh commented Feb 14, 2021

Relates to #130 and #138

fix for #138 borrowed from (MIT-License)

Resources for #138: res1 and maybe res2

@whplh whplh changed the title Use usEffect for SSR, add ref.current to dependency array Use useEffect for SSR, add ref.current to dependency array Feb 14, 2021
@@ -36,7 +38,7 @@ function useResizeDetector<RefType extends Element = Element>(props: FunctionPro
height: undefined
});

useLayoutEffect(() => {
useEnhancedEffect(() => {
if (isSSR()) {
return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a side note: If the hook would actually do something which depends on targetRef these changes would be problematic in some cases (because of const ref: MutableRefObject<null | RefType> = targetRef ?? localRef;)

@@ -81,7 +81,7 @@ const CustomComponent = () => {
import { useResizeDetector } from 'react-resize-detector';

const CustomComponent = () => {
const targetRef = userRef();
const targetRef = useRef();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooops :)

@maslianok maslianok merged commit 3855643 into maslianok:master Feb 16, 2021
@maslianok
Copy link
Owner

Merged. Thanks for your work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants