[英]How to import .jsx files to .js files in reactJS
I m using node.js for this and using react as frontend, Now how do I import app.jsx file to index.js file?我为此使用 node.js 并使用 react 作为前端,现在如何将 app.jsx 文件导入 index.js 文件? index.js
index.js
import App from "./components/app";
ReactDOM.render(<App text="Hello world"/> , document.getElementById('root'))
app.jsx应用程序.jsx
function App(props){
return <h1>{props.text}</h1>
}
export default App;
now at last in app.jsx file I tried to import/require the React file but I get an error "require is not defined"现在终于在 app.jsx 文件中我尝试导入/要求 React 文件,但我收到错误“要求未定义”
Did you type code below at the top in index.js and app.jsx file?您是否在 index.js 和 app.jsx 文件的顶部键入了以下代码?
// app.jsx
import React from "react";
// index.js
import React from "react";
import ReactDom from "react-dom";
or maybe you type "require" code in the wrong line.或者你可能在错误的行中输入了“require”代码。 Check it!
核实!
use npx create-react-app
in your terminal to create new starter react app, you will see the working code over there.在终端中使用
npx create-react-app
创建新的启动反应应用程序,您将在那里看到工作代码。 link for more info https://create-react-app.dev/docs/getting-started链接了解更多信息https://create-react-app.dev/docs/getting-started
if there is "type":"module" in package.json, remove it.如果 package.json 中有 "type":"module",请将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.