-
Notifications
You must be signed in to change notification settings - Fork 46
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
infinite loop with basic hook example in CRA, Gatsby, etc #97
Comments
Hey @fbegue , it might be because you put the query object
within the render function. In this case, each time the component re-renders a new query object is created and the hook will think you are passing in a new query, triggering this loop. In the codesandbox you linked, you have the query outside the render function, and it seems to be working as expected, no loop there. |
You saved my day! |
I'm sure this must be user error - but when I tried to pull the library into my project, anywhere I try to use the hook (and print the params value), the component using it runs itself infinitely. This feels like a loop triggered by the value of the hook changing, but the output is always the same:
App.js:18 {width-between-400-and-599: false, width-larger-than-600: false}
App.js:18 {width-between-400-and-599: false, width-larger-than-600: false}
App.js:18 {width-between-400-and-599: false, width-larger-than-600: false}
you get the idea.
I then tried to make a fresh Gatsby app then a fresh CRA app with just the hook example like so:
But in both cases, same outcome. Looking for help to determine what I'm missing here?
Have a the working example in a codebox here btw, what gives!?
https://codesandbox.io/s/react-container-query-xqvy4
Thanks
The text was updated successfully, but these errors were encountered: