npx create-react-app没有创建JSX文件。

huangapple go评论60阅读模式
英文:

npx create-react-app didn't create JSX file

问题

当我在终端中使用 npx create-react-app <app name> 命令创建 ReactJS 项目时,我默认得到了一些 JS 文件。我是 ReactJS 的新手,根据需求被要求在 JSX 文件中开发代码。但我不确定为什么 npx create-react-app <app name> 命令在终端中没有为我创建任何 JSX 文件。

参考链接:
https://www.jetbrains.com/help/idea/react.html#install_react_in_empty_project

请告诉我,我是否只需将 JS 文件重命名为 JSX,或者为什么 npx create-react-app <app name> 命令没有在 React 项目中创建任何 JSX 文件。

谢谢。

英文:

When I created ReactJS project using npx create-react-app &lt;app name&gt; command in Terminal, I got JS files by default came in the react project. I am new to ReactJS and I was asked to develop code in JSX files as per requirement. But I am not sure why doesn't npx create-react-app &lt;app name&gt; command in Terminal, didn't create even a single JSX file for me.

Reference:
https://www.jetbrains.com/help/idea/react.html#install_react_in_empty_project

Can you please tell me should i just rename JS to JSX or why the npx create-react-app &lt;app name&gt; command didn't create even a single JSX file in the React project.

Thank you

答案1

得分: 1

当您初始化一个项目时,您只有像样板代码一样的文件。您可以开始创建带有.jsx扩展名的文件,并开始编写您的React组件。

英文:

When you initialize a project, you have only the files which are like boilerplate code. You can start creating files with .jsx extension and work on your react components.

答案2

得分: 1

CRA的情况下,.js.jsx 文件几乎没有任何区别。默认情况下,create-react-app 只会创建 .js 文件。如果你想要的话,你必须手动将 app.jsindex.js 的文件扩展名更改为 .jsx。由于导入不需要包含文件扩展名,所以你不需要改变任何其他内容。在React中,这两个扩展名的工作方式完全相同。

英文:

There is rarely any difference between .js and .jsx files as far as CRA is concerned. create-react-app will create only .js files by default. You have to manually change the file extensions of app.js and index.js to .jsx if you want. Since imports don't need to include file-extensions in them, you do not have to change anything else. Both the extensions work exactly the same in react.

huangapple
  • 本文由 发表于 2023年6月22日 14:44:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76529199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定