0

I am new to ReactJS and learning some samples exercises online. Have trouble rendering a simple tag on the browser. Have an Uncaught syntax error that doesnt make sense.

I am returning only 1 tag which was the only nesting issue reported on React related issue in this forum. Can you help me troubleshoot this pls.

Code below

/** @jsx React.DOM */ var MySelect = React.createClass({ getInitialState: function(){ return { selected:false }; } render: function(){ var mySelectStyle = { border: '1px solid #999', display: 'inline-block', padding: '5px' }; return ( //react div element, via JSX, containing <MyOption> component <div style={mySelectStyle}> <MyOption value="Volvo"></MyOption> <MyOption value="Saab"></MyOption> <MyOption value="Mercedes"></MyOption> <MyOption value="Audi"></MyOption> </div> ); } }); var MyOption = React.createClass({ /* render: function(){ return <div> {this.props.value} </div> ; } */ }); ReactDOM.render(<MySelect />, document.getElementById('app')); </script> </body> </html> 
1
  • You should create a pastebin example in this case, it's not so clear to understand where the error appears. Commented Dec 28, 2016 at 12:18

2 Answers 2

2

You need to separate you functions by , . Also make sure you are using babel to transpile your jsx code.

var MySelect = React.createClass({ getInitialState: function(){ return { selected:false }; }, render: function(){ var mySelectStyle = { border: '1px solid #999', display: 'inline-block', padding: '5px' }; return ( //react div element, via JSX, containing <MyOption> component <div style={mySelectStyle}> <MyOption value="Volvo"></MyOption> <MyOption value="Saab"></MyOption> <MyOption value="Mercedes"></MyOption> <MyOption value="Audi"></MyOption> </div> ); } }); var MyOption = React.createClass({ render: function(){ return <div> {this.props.value} </div> ; } }); ReactDOM.render(<MySelect />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="app"></div>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you are right. Yes I missed the , have added it to the code and changed the library to 15.1 as you have shared. Thanks. Have few more errors but may be will compile in Babel without jsx and revert
0

MyOption component is not returning anything here. May be thats the reason for the error.

1 Comment

Have tried uncommenting the return stmt but still errors.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.