Igor N. Igor N. - 1 year ago 143
React JSX Question

React - this.props looks undefined

I'm going through a React tutorial. Here's the code that doesn't work when I add a property to a Greeter object

let Greeter=React.createClass({
render: ()=>{
let name=this.props.name;
return (<div>
<h1>Hello {name}!</h1>

<Greeter name ="Your name"/>,

The doesn't render at all, when I'm using Firefox, here's what I get:

unreachable code after return statementbrowser.min.js:37:6409
TypeError: undefined has no properties

Answer Source

Two things:

  1. You don't need to use a lambda here.
  2. ES6 method implementations do not need a colon (:) after the method name unless you explicitly specify function() { afterwards.


render: ()=>{


render() {

Or if you're unable to use the shorthand function declarations:

render: function() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download