-
Notifications
You must be signed in to change notification settings - Fork 77
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
Getting a "0" instead of my component. #28
Comments
hard to tell without seeing the code. |
ok, here are the chunks that I've changed to add react-dimensions: In the beginning of the file that defines my component, I added this import: import dimensions from 'react-dimensions'; and in the end, in the part where I export the component, I wrapped it in a dimensions()() call: export default dimensions()(CarouselImage); and, in the render method, I added a console.log() to make sure that I am getting the width correctly from the parent component (which has the width specified in css): render() {
console.log(this.props.containerWidth); Turns out that console.log() prints the width correctly, the only problem is that there is a "0" div instead of my component when I inspect the element using chrome developer tools. |
Hi @blechner thanks for sharing more info but it's almost impossible to help solve the problem if I can't reproduce it. If you can share some code that I can run and get the same problem then I can maybe tell if the bug is in react-dimensions. |
I'll see if I can isolate the code and then share... |
I'm getting the same issue. I'll see if I can post some code snippets later |
I think this is the situation that's causing the issue for us:
The Widget component in this render method is what is wrapped in Dimensions. We have it stored in an object, which is where we render it from. Technically, Widget in this case is an arrow function that returns the component. We're using Dimensions in a few other areas of the app and it works perfectly, but this is where we see the problems. FYI one thing that's interesting is it only seems to happen when we're using flexbox on the outer components (sometimes), and sure enough if you resize the window it starts rendering the component again. |
Here's what I recommend for troubleshooting: using the chrome web inspector check the size of the wrapper div that |
I've just tried to use Dimensions in a public git project I have so I could show you, but it worked perfectly there... |
I've inspected the element and saw this:
Not sure if I understood your suggestion... so I need to pass containerStyle to react-dimensions? What should I pass as containerStyle? I am not an expert in css. How do I know if my problem is this "flexbox" that you mentioned? |
What you need to look for in the inspector is the rendered height and width of the |
If you're still having problems try the latest version on |
I've just tried the latest version but the problem is still there. |
I got this issue too and I'm using flex-box to style the container and react-dimension return 0px height but actually the container have 598px of height. My application have 2 route, one route contains normal form and the second contains the fixed-data-table with react-dimension, if I start from "form" page then change route to the second page, everything is fine. But if I enter the second route for the first time I load my application react-dimension will return 0px of height |
@nhducit as with previous times this issue has arisen, it is impossible to fix without sharing code that replicates the problem. |
Hi @gmaclennan
In the test console, it always render: I tried your suggetion as: It becomes like this: Any help pls? |
I'm getting the same issue, but I'm not using this lib. I'v created a custom tooltips component that wraps around some other components or markup. If the child elements containers are floated left, then I get
|
@conor909 The "0" in this module is due to this line:
in For all other people having the issue, having a "0" content means that either @gmaclennan Maybe to prevent more people reporting this issue, a clearer message could replace the "0" when one of the dimensions is zero. Because there is no case where you want the actual "0" to appear in your browser anyway, so better replace it with something like "[zero-size-component]", or send a console warning. |
Another option is to ensure that
|
This would probably fix it: #64 Sorry I haven't really had any time to maintain this module, maintainers welcome! If someone tests that PR and it works I'll go ahead and merge, no time to test here. I based it on the v1.3.0 branch, is that what people are using? Or the v2 alpha? |
If you encounter this issue and aren't using react-dimensions, jdelafon's explanation above may still apply to you. It's not specific to this lib. Suppose you're loading data from a backend that returns booleans as 0 or 1 (e.g tinyInt). For example
showWarning may be 0 rather than false. Wrapping the expression in Boolean() will avoid unexpected int literals. |
Thank you @MarcusJay this was the solution to my problem!!! 🥇 |
I've just found this and I am trying to use it. I am having the same problem as @jdelafon in issue #1 . I wrapped my component with Dimensions()(MyComponent) and all I see is a "0" rendered instead of MyComponent. The parent component has width specified and I can access this.props.containerWidth in MyComponent's render() method, but I don't understand why I am getting a "0" div. If manually resize the browser window, then I can see MyComponent rendered normally. Am I missing something? Should I add code to force a resize event?!
The text was updated successfully, but these errors were encountered: