[英]Not able to find real difference between .jsx and js file
My .js file is:-
我的.js文件是:-
var React = require('react');
export default class AmortizationChart extends React.Component {
render() {
var items = this.props.data.map(function (year, index) {
return (
<tr key={index}>
<td>{index + 1}</td>
<td className="currency interest">{Math.round(year.interestY).toLocaleString()}</td>
<td className="currency">{Math.round(year.balance).toLocaleString()}</td>
</tr>
);
});
Now same I can Write also in .jsx file.So what is the difference which file I sould take .js or .jsx?
现在我也可以在.jsx文件中写入文件。那么我选择的.js或.jsx文件有什么区别?
This bit is JSX: 这是 JSX:
<tr key={index}>
<td>{index + 1}</td>
<td className="currency interest">{Math.round(year.interestY).toLocaleString()}</td>
<td className="currency">{Math.round(year.balance).toLocaleString()}</td>
</tr>
This only works because you're loading your .js file as text/babel
. 这仅适用,因为您正在将.js文件加载为
text/babel
。 Try it with text/javascript
and you'll get the following error: 尝试使用
text/javascript
,您将收到以下错误:
Uncaught SyntaxError: Unexpected token <
未捕获到的SyntaxError:意外令牌<
React's own documentation has a good article on JSX here: JSX In Depth . React自己的文档在JSX上有一篇不错的文章: JSX In Depth 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.