You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there any way to reference the instance child from within the Parent?
The same is valid if I want to reference the state within the child:
child.data.foo='bar';
At the moment, child is instantiated automatically by Parent and never exposed the outside world. That means that I'm not able to reference any of the methods on that instance (e.g. state, listeners, etc.). I was thinking perhaps component.components could hold a reference to a children already instantiated, rather than class? In this way we could manipulate the new instance like below:
Unfortunately, there is no way to get instances of child components for now, but if you'd like to just add a listener you can do that like the following:
// first, add id or class name to the child .varChild=hyperd.Component.extend({render: function(){return'<div id="child">'+this.data.count+'</div>';}})// listen an event of the child in the parent component.this.on('click','#child',console.log.bind(console));
Otherwise, we should add a new feature to get references of child components, maybe something like:
// add a special attribute to the node
render: function(){return'<div><child data-ref="child1"/></div>';}// access to the referencethis.refs.child1.data.foo=bar;
component.components requires classes of components because any number of child components can be dynamically instantiated.
Additionally, you can set properties of child components instead of data when rendering, so I think you don't need to access these instances in most cases.
// parentrender: function(){// instead of child.data.foo = bar;return'<div><child foo=" + bar + "/></div>'}[...]// childrender: function(){return'<div>foo:'+this.props.foo+'</div>'}
Consider the following snippet taken from the tests:
I'd like to attach a listener to the
Child
like this:is there any way to reference the instance
child
from within the Parent?The same is valid if I want to reference the state within the child:
At the moment,
child
is instantiated automatically byParent
and never exposed the outside world. That means that I'm not able to reference any of the methods on that instance (e.g. state, listeners, etc.). I was thinking perhapscomponent.components
could hold a reference to a children already instantiated, rather than class? In this way we could manipulate the new instance like below:Thoughts?
The text was updated successfully, but these errors were encountered: