gpt4 book ai didi

javascript - ReactJS 无法识别

转载 作者:行者123 更新时间:2023-12-03 01:17:00 25 4
gpt4 key购买 nike

这是我的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 确认

如果您希望从头开始组织应用程序结构,则需要安装 reactreact-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;

了解更多信息:https://github.com/facebook/create-react-app

关于javascript - ReactJS 无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51963528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com