这是我的index.html
文件
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="hello"></div>
<script type="text/jsx" src="app/index.js"></script>
</body>
</html>
这是我的index.js 文件。
var React = require('react');
var ReactDOM = require('react-dom');
var createReactClass = require('create-react-class');
var App = React.createClass({
render: function(){
return(
<h1>Hello</h1>
);
}
});
ReactDOM.render(<App/>,document.getElementById('hello'));
I am not able to see hello on the webpage which I should be seeing
React 开发者工具也说这个页面不是 React
错误是什么?
最佳答案
使用create-react-app
引导您的应用程序并在 src 文件夹中添加组件。要引导 React 应用程序,您需要安装 Node js(版本 >= 6 ),使用 node -v
确认
如果您希望从头开始组织应用程序结构,则需要安装 react 和 react-dom强>使用npm install react react-dom
您可以使用命令 npx create-react-app appName
引导 React 应用程序。示例 React 文件如下所示:
import React, { Component } from "react";
class ComponentName extends Component {
render() {
return (
<div>
Page contents
</div>
);
}
}
export default ComponentName;
关于javascript - ReactJS 无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51963528/