Skip to content
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

onResize fires with empty object #138

Open
vineetit1991 opened this issue May 9, 2019 · 2 comments
Open

onResize fires with empty object #138

vineetit1991 opened this issue May 9, 2019 · 2 comments

Comments

@vineetit1991
Copy link

vineetit1991 commented May 9, 2019

Error:- Uncaught TypeError: Cannot read property 'width' of undefined

<Measure
    onResize={({ entry: { width, height } }) => dispatch({
        type: XXXX_XXXXX,
        payload: {
            width: Math.ceil(width),
            height: Math.ceil(height)
        }
    })}
>

Version:- 2.3.0

@souporserious
Copy link
Owner

Ah, sorry I should have made this more clear in the 2.3.0 release that this could be a breaking change. It would probably be best to just bail out of onResize if no measurements were found on mount.

@souporserious
Copy link
Owner

This should fix the issue for now:

<Measure
    onResize={({ entry }) => entry && dispatch({
        type: XXXX_XXXXX,
        payload: {
            width: Math.ceil(entry.width),
            height: Math.ceil(entry.height)
        }
    })}
>

I'll think about a better solution here. Do you think the existence of entry is enough? The unfortunate part is it needs to fire onResize both in componentDidMount and the resize observer, that's why there are two calls to onResize on initial render 😞.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants