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

Render props pattern usage #105

Closed
chrisdrackett opened this issue Feb 18, 2017 · 8 comments
Closed

Render props pattern usage #105

chrisdrackett opened this issue Feb 18, 2017 · 8 comments

Comments

@chrisdrackett
Copy link

chrisdrackett commented Feb 18, 2017

Have you ever considered having sizeMe work where you use a <SizeMe> component and it passes the size down as a prop? I think this method feels a bit more readable. ReactMotion does something like this.

<SizeMe monitorHeight>
    {size => <div>{size.width}, {size.height}</div>}
</SizeMe>
@ctrlplusb
Copy link
Owner

It's an interesting concept. Although we would have to make the SizeMe component render out a div or something similar, which would then be measured and then it's size would be passed down into the render callback function.

Additional props could be applied to the div (outside of the expected SizeMe config props) - such as className/style etc, and we could even support a tag prop so you can change the container type (e.g. div/span etc).

This could be just a special component that encapsulates the existing API. Are you happy to experiment in creating this wrapper component? And then we could look at incorporating it if we found it useful.

@chrisdrackett
Copy link
Author

chrisdrackett commented Apr 3, 2017

could SizeMe just clone and return its child and make sure that only a single child is ever sent?

@ctrlplusb
Copy link
Owner

Yeah, that sounds like an option. 😀

I would love for us to explore this more. Are you up for starting up a PR?

@chrisdrackett
Copy link
Author

I am!

@ctrlplusb
Copy link
Owner

Awesome! Shout if you need anything. 😊

@chrisdrackett
Copy link
Author

actually I might have spoken too soon, I'm going to take a look at https://github.com/souporserious/react-measure first, as it seems to support this format already and we have other components that also use it already.

Not that I'm against helping out, it just might not be right away 😊

@ctrlplusb
Copy link
Owner

Started to flesh out an API: https://codesandbox.io/s/oxkw6xv4z6

@ctrlplusb ctrlplusb changed the title Let <SizeMe> work as a wrapper component? Render props pattern usage May 28, 2018
@ctrlplusb
Copy link
Owner

Published a new version including a render props pattern based component 🎉

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