-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Does not work with flexbox #29
Comments
There seems to be something wrong with the variable names. Only
works. const App = () => {
const [open, setOpen] = useState(true);
const { ref, width, height } = useResizeObserver();
const { ref2, width2, height2 } = useResizeObserver();
const { ref3, width3, height3 } = useResizeObserver();
const renderDiv = () => {
if (!open) {
return null;
}
return (
<div
ref={ref2}
style={{ flexGrow: "1", backgroundColor: "orange", padding: "1em" }}
>
{width2}x{height2}
</div>
);
};
return (
<div>
<button onClick={() => setOpen(!open)}>Toggle</button>
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "stretch"
}}
>
<div
ref={ref}
style={{ flexGrow: "1", backgroundColor: "teal", padding: "1em" }}
>
{width}x{height}
</div>
{renderDiv()}
<div
ref={ref3}
style={{ flexGrow: "1", backgroundColor: "violet", padding: "1em" }}
>
{width3}x{height3}
</div>
</div>
</div>
);
}; |
You're using object destructuring wrong, try something like: const {ref, width: width2, height: height2} = resizeObserver() Then it should work 👍 |
Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minimal example that uses flex boxes that does not work. Link
The text was updated successfully, but these errors were encountered: