I have a react component like below:
var Dog = React.createClass({
bark: function() {
alert('bow');
},
render: function() {
return (<div>Dog</div>);
}
});
But when I am trying to call the bark
method by creating an element of Dog
like below:
var doge = React.createElement(Dog, null);
console.log(doge);
doge.bark();
I am getting Uncaught TypeError: doge.bark is not a function
. But in chrome's console I can see the bark method in doge
object
I am a beginner in react. Can anyone explain what is actually going on behind the scenes?
EDIT:
Actually I want to know why we can not access a component's method from its element created by React.createElement
method? Please someone explain this.