Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Do not render "0" when parent height and width are both 0.#61

Open
stonebk wants to merge 4 commits intoawana-archive:masterfrom
stonebk:master
Open

Do not render "0" when parent height and width are both 0.#61
stonebk wants to merge 4 commits intoawana-archive:masterfrom
stonebk:master

Conversation

@stonebk
Copy link
Copy Markdown

@stonebk stonebk commented Mar 8, 2017

The following will render "0":

const Foo = Dimensions()(() => <div />);
const Bar = () => {
    return <div style={{ width: 0, height: 0 }}><Foo /></div>;
};

Comment thread index.jsx
<div style={wrapperStyle} ref='wrapper'>
{(containerWidth || containerHeight) &&
<ComposedComponent
{(containerWidth || containerHeight)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way you are not creating the ComposedComponent if the dimensions are 0. This may lead to some confusion.
You could solve the printing of '0' by casting the above statement to a boolean like this !!(containerWidth || containerHeight)

Copy link
Copy Markdown
Author

@stonebk stonebk Mar 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ComposedComponent is already not being created. {(0 || 0) && <ComposedComponent>} becomes {0} which will render "0" as text. {(0 || 0) ? <ComposedComponent> : null} becomes {null} which will render nothing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed true and a derp on my part. Disregard my comments ;)

@gabegorelick
Copy link
Copy Markdown

Any plans to merge this?

@yocontra
Copy link
Copy Markdown

Yeah, this is a pretty weird bug - would be great to have this merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants