width and height undefined if "ref div" is located after conditional rendering
See original GitHub issueHi Masianok,
thanks for the library.
I have the following problem:
const [result, reexecuteQuery] = useGetMissionsTimeLineQuery({
variables: {
id: "7d99fb36-936b-4f40-81e6-0cbfce5190da",
isActive: true,
memberId: "xxxx",
},
});
const { data, error, fetching } = result;
const onResize = useCallback(
() => {
console.log('resize')
},
[],
)
const { width, height,ref } = useResizeDetector({onResize});
...
return <div ref={ref}>{`${width}x${height}`}</div>
`
work accordingly description.
But if I add: conditions before the final div:
if (!data) return <div>Loading</div>;
if (fetching) return <div>Loading</div>;
if (error) return <div>error</div>;
return <div ref={ref}>{`${width}x${height}`}</div>
witdh
and height
are undefined for ever.
Is it a bug, or did I use the library wrong ? Thanks for your help.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to get the size (height/width) of a specific instance of a ...
I am trying to simply get the width & height of one of the rendered <div/> on Child.js . This is a great...
Read more >Input Components - React-admin - Marmelab
Input components must be used inside a Form element (e.g. <Form> , <SimpleForm> ... If true , the input will expand to fill...
Read more >Testing element dimensions without the browser
current value starts as null , I can't compute the width on the initial render. To solve this problem, I used the onMouseEnter...
Read more >Passing Props to a Component - React Docs
The default value is only used if the size prop is missing or if you pass size={undefined} . But if you pass size={null}...
Read more >Making Sense of react-spring - CSS-Tricks
useHeight gives us a ref and a height value of the content we're measuring ... Since a modal is conditionally rendered based on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is pretty nerve racking. I have tried all kinds of settings (refreshMode, -rate, -Options). Without any I get undefined and it stays that way. With
the component renders twice after receiving the width. But id does return a width value.
So:
I have conditional rendering too. But removing it seemed to change nothing.
Thank for the info. I corrected the links.