我是React的新手,我用以下解释来构建基本的React应用程序:https : //facebook.github.io/react/docs/installation.html
我通过以下方式打开了一个新项目:
npm install -g create-react-app
create-react-app my-app
cd my-app
npm start
Run Code Online (Sandbox Code Playgroud)
index.html文件位于hello-world / public中,其内容是:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是,所有“反应材料”都放在hello-world \ src目录中。看起来“ hello-world \ src \ index.js”激活了这些组件。
我不明白的是index.html如何“读取” index.js的内容。index.html没有指向index.js的html标记。
我可以通过“ npm start”启动该应用程序。该命令的作用是提高运行在localhost:3000上的服务器。不使用“ npm start”如何查看应用程序?
关于在使用create-react-app构建Chrome扩展程序时如何实现实时重新加载的任何建议?目前我yarn run build每次都有变化。
以前我style.less像这样导入了bootstrap (不使用js框架):
@import "bootstrap/less/bootstrap.less";
@import "variables.less";
@import "mixins.less";
@import "main.less";
...
Run Code Online (Sandbox Code Playgroud)
现在create-react-app,我为每个组件使用单独的文件夹,并使用单独的sass文件(被告知这是最好的方法之一)。
??? components
? ??? About
? ? ??? index.jsx
? ? ??? style.css
? ? ??? style.scss
? ??? App
? ? ??? App.test.js
? ? ??? index.jsx
? ? ??? style.css
? ? ??? style.scss
? ??? Bread
? ? ??? index.jsx
? ? ??? style.css
? ? ??? style.scss
? ??? Delivery
? ? ??? index.jsx
? ? ??? style.css
? ? …Run Code Online (Sandbox Code Playgroud) 我有一个简单的测试文件设置,几乎与create-react-app使用的文件相同:
App.test.js
import React from 'react';
import ReactDOM from 'react-dom';
import { App } from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
Run Code Online (Sandbox Code Playgroud)
当我运行时,yarn test我不断收到此错误消息:
Invariant Violation: Could not find "store" in either the context or props of "Connect(App)". Either wrap the root component in a <Provider>, or explicitly pass "st
ore" as a prop to "Connect(App)".
我已经尝试在我的App.js文件中执行单独的导出并导入非Redux组件,但我仍然无法使其工作.以下是我涉及的另外两个文件:
App.js
import React, { Component } from 'react';
import axios from 'axios';
import …Run Code Online (Sandbox Code Playgroud) 我安装create-react-app没有-g
C:\Users\user1\projects\react>npm install create-react-app
但是当我跑
C:\Users\user1\projects\react>create-react-app my-app1
我收到以下错误
'create-react-app' is not recognized as an internal or external command, operable program or batch file.
任何人都可以帮我理解-g旗帜的作用
如果我不想全局安装怎么办?
如何在没有全局安装的情况下使其工作?
是否可以将一组图像作为数组导入?(create-react-app项目)像下面写的一样,但是单行显示?
import Hat1 from '../../assets/img/accesories/hats/hat1.png';
import Hat2 from '../../assets/img/accesories/hats/hat2.png';
import Hat3 from '../../assets/img/accesories/hats/hat3.png';
import Hat4 from '../../assets/img/accesories/hats/hat4.png';
import Hat5 from '../../assets/img/accesories/hats/hat5.png';
import Hat6 from '../../assets/img/accesories/hats/hat6.png';
const hatsArr = [
Hat1,
Hat2,
Hat3,
Hat4,
Hat5,
Hat6
];
Run Code Online (Sandbox Code Playgroud) 使用create-react-appwith react-scripts-ts与TypeScript 一起使用时,运行带有--coverage标志的测试会导致错误的覆盖率报告。有什么方法可以整合ts-jest,以便覆盖率报告准确无误?
下面是我在开玩笑的配置package.json:
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"mapCoverage": true,
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是我收到的错误消息:
Out of the box, Create React App only supports overriding these Jest options:
• collectCoverageFrom
• coverageReporters
• coverageThreshold
• snapshotSerializers.
These options in your package.json Jest configuration are not currently supported …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个正在运行的React.js应用程序npx create-react-app my-app,但我不希望在生产模式下在devtools中使用完整的项目。
如何在“源”选项卡(devtools)中禁用或隐藏节点模块和webconfig?
我签入了其他已部署的react应用程序,该应用程序未显示静态文件夹或整个项目;我怎样才能做到相同?
下面是浏览器“来源”标签的控制台屏幕截图,显示了一些我想向公众隐藏的目录;

我jsx-a11y/accessible-emoji从使用表情符号的Create React App 获得警告。
为了解决这个问题,我尝试制作具有可访问性要求的组件,但是我仍然收到警告:
const EmojiWrap = props => {
return (
<span role="img" aria-label="sheep">
{props.children}
</span>
);
};
<EmojiWrap></EmojiWrap>
Run Code Online (Sandbox Code Playgroud)
我相信这应该工作,所以这可能是eslint的错误/创建react应用程序的错误吗?
我也尝试过使用 aria-hidden="true"
Recently, React started giving depreciation warnings for componentWillReceiveProps lifecycle method. I am using a library that utilized this function and the maintainers haven't updated their codebase yet.
Currently, any time I run my tests, whether it is in development or in CI, I keep getting ~30 lines of depreciation warnings for each component that the maintainer provides.
Is there a way to suppress these warnings (at least in development)?
EDIT:
I am willing to add certain comments in my files …
create-react-app ×10
reactjs ×7
javascript ×2
jestjs ×2
bootstrap-4 ×1
devtools ×1
emoji ×1
es6-modules ×1
import ×1
jest ×1
npm-install ×1
production ×1
react-redux ×1
typescript ×1