How to get the value from the reacting function inside the reacting component

I am new to Reacj.js and cannot get value from function. I am not sure that I am doing it right. I need a func function expression to return "from func" and replace {this.func}. Not sure what I am missing.

var Hello = React.createClass({ func: function(){ return 'from func'; }, render: function() { return <div> <div>Props: {this.props.name}</div> <div>Function: {this.func}</div> </div>; } }); React.render(<Hello name="from props" />, document.getElementById('container')); 

I have a js script in http://jsfiddle.net/rexonms/409d46av/

+5
source share
1 answer

You are almost there. Remember that everything inside {and} in JSX is just plain Javascript. And in order to get the return value from the function in Javascript, you have to call it. So something like this (note the parens after this.func ):

 return ( <div> <div>Props: {this.props.name}</div> <div>Function: {this.func()}</div> </div> ); 
+18
source

All Articles