Hacker News new | ask | show | jobs
by d0m 4000 days ago
About the refs, I've been using a small helper:

    h.ref(this, 'some-element.children-element');
and its companion h.$ref(this, 'some-element.children..'); for the jquery version.

I don't have a strict rule of when using it, but sometimes it's cleaner than having lots of nested callback on an inner children.. I.e. I can just do:

    h.$ref(this, 'header.search.input')..
Which basically transforms to this.refs.header.refs.search.refs.input (IIRC)
2 comments

I wouldn't encourage doing that because it breaks encapsulation of your children. Like state, you shouldn't peer into another component's refs.

But that should continue to work fine.

I think it's fine when the parent and children are really tied together. I wouldn't use that from the main component to a really nested children for instance.

Let's say you have a "SearchComponent" with a "SearchButtonComponent" and "SearchInputComponent", I'm okay with using the strategy I suggested because using "SearchInputComponent" without its parent somewhere else in the code would be too risky so the encapsulation is still kept between parent/children.

This doesn't sound like a good idea and seems to defeat the purpose of componentization in the first place.