Coding Duchess
Coding Duchess

Reputation: 6899

ReactJS examples fail

I am using the following example from ReactJS tutorial:

const Button = function() {
   return {<button>Go</button>;
   };

};
ReactDOM.render(<Button/>, mountNode);

I tried it both in a file and int Javascript REPL and getting the same error:

  SyntaxError: unknown: Unexpected token (4:9)
  2 | 
  3 | const Button = function() {
> 4 |   return {<button>Go</button>;
    |           ^
  5 |   };
  6 | 
  7 | };

Cannot figure out what is wrong - it seems to work fine in the same setting in the tutorial video.

Upvotes: 0

Views: 35

Answers (2)

Dresha
Dresha

Reputation: 96

You should change brackets return {<button>Go</button>;}; to return(<button>Go</button>);

Upvotes: 1

Shubham Khatri
Shubham Khatri

Reputation: 281616

You component is a function component and you don't wrap the returned Elements within {}. If you do it means you are returning an object

const Button = function() {
   return <button>Go</button>;

};
const mountNode= document.getElementById('app');
ReactDOM.render(<Button/>, mountNode);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.min.js"></script>
<div id="app"></div>

Upvotes: 0

Related Questions