Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
70
rated 0 times [  75] [ 5]  / answers: 1 / hits: 29847  / 11 Years ago, fri, january 3, 2014, 12:00:00

I'm doing the React.js tutorial from http://facebook.github.io/react/docs/tutorial.html. Here are my files:



template.html:



<html>
<head>
<title>Hello React</title>
<script src=http://fb.me/react-0.8.0.js></script>
<script src=http://fb.me/JSXTransformer-0.8.0.js></script>
<script src=http://code.jquery.com/jquery-1.10.0.min.js></script>
</head>
<body>
<div id=content></div>
<script type=text/jsx src='tut.js'>
</script>
</body>
</html>


and tut.js:



/** @jsx React.DOM */

var data = [
{author: 'Tldr', text: 'This is a comment'}
]

var CommentBox = React.createClass({
render: function() {
return (
<div className='commentBox'>
<h1>Comments</h1>
<CommentList data={this.props.data} />
<CommentForm />
</div>
)
}
})

var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function(comment) {
return <Comment author={comment.author}>{comment.text}</Comment>
})
return (
<div className='commentList'>
{commentNodes}
</div>
)
}
})

var CommentForm = React.createClass({
render: function() {
return (
<div className='commentForm'>
Hello World, I am a comment
</div>
)
}
})

var Comment = React.createClass({
render: function() {
return (
<div className='comment'>
<h2 className='commentAuthor'>
{this.props.author}
</h2>
{this.props.children}
</div>
)
}
})

React.renderComponent(
<CommentBox data={data} />,
document.getElementById('content')
)


But when I open it in the browser, I just see a blank page without any comments. What am I doing wrong?


More From » reactjs

 Answers
14

Chrome doesn't let you load file:// urls via XHR (which as mentioned elsewhere is how the in browser transform works). You have a couple options:




  • Use a different browser. I know Firefox works.

  • Start a local web server (Python ships with one, so if you have that installed it's very simple - http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python).

  • Put the script inline instead of in a separate file. That's doable for something simple like this but you'll want to try one of the other options as your code gets more complicated.


[#73395] Thursday, January 2, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;