React with ES6を使用してコンポーネントへの参照を取得するにはどうすればよいですか?Es6 Reacts to components
私はコンポーネントA
class ComponentA extends React.Component {
doSomethingInComponentA() {
//do Something here..
}
}
render(<ComponentA />, document.getElementById('container'));
を持っていると私はComponentAのメソッドを呼び出したい別のコンポーネント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
を取得し、私のエントリポイントは、このための任意の回避策はありますか?
AとBはどのように接続されていますか? – nils
彼らは直接接続していない..私は他のコンポーネントからメソッドを呼び出す方法を知りたいだけです –
流行を避けたい場合は、これを見てください:http://andrewhfarmer.com/component-communication/ – nils