मैं एक घटक को एक प्रतिक्रिया तत्व के उदाहरण से एक प्रतिक्रिया घटक द्वारा उजागर करना चाहता हूं।
उदाहरण के लिए, इस jsfiddle में । मैं संदर्भ alertMessageसे विधि को कॉल करना चाहता हूं HelloElement।
क्या अतिरिक्त रैपर लिखने के बिना इसे प्राप्त करने का एक तरीका है?
संपादित करें (JSField से कॉपी किया गया कोड)
<div id="container"></div>
<button onclick="onButtonClick()">Click me!</button>
var onButtonClick = function () {
//call alertMessage method from the reference of a React Element! Something like HelloElement.alertMessage()
console.log("clicked!");
}
var Hello = React.createClass({displayName: 'Hello',
alertMessage: function() {
alert(this.props.name);
},
render: function() {
return React.createElement("div", null, "Hello ", this.props.name);
}
});
var HelloElement = React.createElement(Hello, {name: "World"});
React.render(
HelloElement,
document.getElementById('container')
);