如何使用 React 和 ES6 获取对组件的引用?
我有一个组件 A
class ComponentA extends React.Component {
doSomethingInComponentA() {
//do Something here..
}
}
render(<ComponentA />, document.getElementById('container'));
还有另一个我想调用 ComponentA 方法的 Component B
class ComponentB extends React.Component {
doSomethingInComponentB() {
ComponentAInstance.doSomethingInComponentA()
}
}
如何获得对 ComponentA 的引用?我试过使用
var ComponentAInstance = render (<ComponentA />,
document.getElementById('container'))
export default ComponentAInstance;
但是由于我使用的是 Webpack 并且 ComponentA.jsx 是我的入口点,所以我得到了错误
Module not found: Error: a dependency to an entry point is not allowed
有什么解决方法吗?