But if i will wrap Modal component via create container i will canât get access for Modal methods. Instead in ârefâ will store react-meteor-data constructorâŚ
How can i get access to child component methods from parent component directly?
Thank you!
Not sure exactly what you are trying to do, but I think I recently did something similar. My click event was inside the Modal component along side of the default closed modal and only text displayed or rendered initally. So with this, I was able to handle open/close functionality inside the Modal component itself.
Thank you for reply!
But the question is how to get the child component methods, taking into account that the child-component is wrapped by meteor-react-data container.
Of course i can define states of modal component in parent, and it is a easiest way. But in fact, i want find more elegant decision.
May be react-meteor-data component have method, what can provide methods and states of wrapped component?
Not sure if you can access a child componentâs refs directly, may someone can chime in for help on that one. But you can pass the parent back data by a calling a prop function that you passed to the child from that parent.
In your example you can use parent methods from child.
I need use child methods, from parent.
For example we have profile page.
And we wanna render Uploader-Modal component (child) when user click on âChange avatarâ button in Profile (parent on this case) component. It is not problem, if Uploader-Modal not wrapped via create Container. But if it did, we canât call show-toogle methods of this child component directly.
Interesting concept of what you are trying to achieve. I was trying some things according to your snippet and once I got this error:
warning.js:36 Warning: MeteorDataContainer: ref is not a prop. Trying to access it will result in undefined being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)
Not sure if youâve gotten that error already or if it helps you.
The createContainer implementation is straighforward and there is no direct way to do what you want. The container component would have to forward the call to the wrapped component and this seems cumbersome.
One way to solve this is to the main component pass a function that the child component uses to register the component instance (using ref on render). Something like this:
class Main {
...
registerModal(component) {
this.modal = component
}
...
render() {
return
}
}
class Modal {
...
render() {
return this.props.registerModal(c)}>
...
}
}
Actually the code above is not registering Modal instance, but the instance of the DIV⌠But in your case you will probably want to register the function that sets the state directly.
I have the same problem.
It looks like they wanted to implement some functionality for that. Because in refs I found âsetStateâ - which just doesnât work, parameter âstateâ which shows me nothing. Totally lost all of the method, I created in the component and want to use in parent container. I can only smile and leave it as it is⌠@sashko Thank you.