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

useWindowDimensions causes infinite re-rendering #2083

Closed
bear-ei opened this issue Feb 23, 2024 · 3 comments
Closed

useWindowDimensions causes infinite re-rendering #2083

bear-ei opened this issue Feb 23, 2024 · 3 comments
Labels
bug Something isn't working Needs: Triage 🔍

Comments

@bear-ei
Copy link

bear-ei commented Feb 23, 2024

Environment

react-native -v: 0.72.9
npm ls react-native-macos: 0.72.13
node -v: 21.4.0
npm -v: 10.2.4
yarn --version: 4.0.2
xcodebuild -version: Xcode 15.2 Build version 15C500b

Steps to reproduce the bug

Try to drag and drop to change the application window size after using useWindowDimensions.

export const Tooltip: FC<TooltipBaseProps> = () => {
    const windowDimensions = useWindowDimensions();

    return (
        <View>
            <Text>{windowDimensions.width}</Text>
        </View>
    );
};

Expected Behavior

No response

Actual Behavior

No response

Reproducible Demo

No response

Additional context

▶︎ 'Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.',

@bear-ei bear-ei added the bug Something isn't working label Feb 23, 2024
@Saadnajmi
Copy link
Collaborator

I don't repro this with RNTester on either 0.72 or 0.73. Are you sure there isn't an extra setState somewhere in your app?

Screen.Recording.2024-02-22.at.11.06.40.PM.mov

@bear-ei
Copy link
Author

bear-ei commented Feb 23, 2024

I don't repro this with RNTester on either 0.72 or 0.73. Are you sure there isn't an extra setState somewhere in your app?

Screen.Recording.2024-02-22.at.11.06.40.PM.mov

Thanks for your reply, my situation is a bit complicated, I'm building a reusable UI component and just introduced useWindowDimensions() , the component doesn't depend on it for the behavior of setState then it shows "Maximum update depth exceeded" and the error stack points to setState in useWindowDimensions, I think I need to double-check the problem.

@bear-ei bear-ei closed this as not planned Won't fix, can't repro, duplicate, stale Feb 23, 2024
@Saadnajmi
Copy link
Collaborator

FWIW, React Native macOS also just supports setting the tooltip prop on any View/Text/Image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Triage 🔍
Projects
None yet
Development

No branches or pull requests

2 participants