[英]JSX not showing in browser
Hi there I recently started following a crash course of Django Rest Framework + React but I came across a problem with my React code.嗨,我最近开始学习 Django Rest Framework + React 的速成课程,但我的 React 代码遇到了问题。 The jsx I write in my App.js
doesn't show in the browser.我在App.js
中编写的App.js
没有显示在浏览器中。 Here is the code:这是代码:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Header from './layout/Header';
import Dashboard from './leads/Dashboard';
import { Provider } from 'react-redux';
import store from '../store';
class App extends Component {
render() {
return (
<Provider store={store}>
<Header />
<div>
<Dashboard />
</div>
</Provider>
)
}
}
ReactDOM.render(<App />, document.getElementById("app"))
He are my Header.js
, and Dashboard.js
files(in case it helps)他是我的Header.js
和Dashboard.js
文件(以防万一)
import React, { Component } from 'react';
export class Header extends Component {
render() {
return (
<div>
<nav className="navbar navbar-expand-sm navbar-light bg-light">
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarTogglerDemo01">
<a className="navbar-brand" href="#">Django + React</a>
<ul className="navbar-nav mr-auto mt-2 mt-lg-0">
</ul>
</div>
</nav>
</div>
)
}
}
export default Header;
import React from 'react';
import Form from './Form';
import Leads from './Leads';
export default function Dashboard() {
return (
<div>
<Form />
<Leads />
</div>
);
}
In case you need any extra information please tell me.如果您需要任何额外的信息,请告诉我。 Can anyone please help me solve this problem??谁能帮我解决这个问题?? If so please tell me and thank you in advance.如果是这样,请告诉我并提前致谢。
Edit: Here is my package.json
file编辑:这是我的package.json
文件
{
"name": "DjangoReact",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development --watch ./backend/frontend/src/index.js --output-path ./backend/frontend/static/frontend",
"build": "webpack --mode production ./backend/frontend/src/index.js --output-path ./backend/frontend/static/frontend/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.7",
"@babel/preset-env": "^7.12.7",
"@babel/preset-react": "^7.12.7",
"babel-loader": "^8.2.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"webpack": "^5.6.0",
"webpack-cli": "^4.2.0"
},
"dependencies": {
"prop-types": "^15.7.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-react": "^1.2.0",
"react-redux": "^7.2.2",
"react-thunk": "^1.0.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0"
}
}
You will not see jsx files in the browser.您不会在浏览器中看到 jsx 文件。 The code from jsx files is transformed into html+js code and displayed in the web browser.来自 jsx 文件的代码转换为 html+js 代码并显示在 Web 浏览器中。
Before going to write your own code, please make sure that you have node.js
installed and that you can run React template code:在编写你自己的代码之前,请确保你已经安装了node.js
并且你可以运行 React 模板代码:
# create the React boilerplate project
npx create-react-app frontend
# go to the fronted project directory
cd frontend
# run React built-in development server
npm start
After the above commands, you should see a default web app at http://localhost:3000
.执行上述命令后,您应该会在http://localhost:3000
看到一个默认的 Web 应用程序。
You can check details in my article: Starting SaaS with Django and React您可以在我的文章中查看详细信息: 使用 Django 和 React 启动 SaaS
If you are able to see the default application then you can start to add your code.如果您能够看到默认应用程序,则可以开始添加代码。 Here you have the second part of my article: React Routing and Components for Signup and Login这是我文章的第二部分: React Routing and Components for Signup and Login
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.