Original question: https://github.com/acdlite/recompose/issues/232
How can I access the ref of the BaseComponent or any level of the components?
Code:
class BaseComponent {
doSth(){...}
}
const Component compose(...some)(BaseComponent);
class App {
componentDidMount() {
// undefined(doSth) is not a function
this.refs.component.doSth();
}
render() {
<Component ref="component" />
}
}
You can use hoistStatic.
class BaseComponent {
doSth(){...}
}
const enhance = compose(...some)
const Component = hoistStatics(enhance)(BaseComponent)
class App {
componentDidMount() {
this.refs.component.doSth()
}
render() {
<Component ref="component" />
}
}
You can find a real example in the test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With