如果是这样,请分享文件夹结构(语义路径在哪里)和导入组件的示例.
我在我的React应用程序中使用antd设计.
这是我面临问题的代码片段:
<Select
showSearch
optionFilterProp = "children"
placeholder = "Select Company"
value = "{this.state.company}"
name = "company"
onSelect = "{this.handleCompanyChange}"
>
Run Code Online (Sandbox Code Playgroud)
现在它显示正确的值,如果this.state.company不是null.但如果this.state.company是,empty或者null占位符没有出现.
如何解决此问题,以便占位符出现,如果value为null?
我需要在使用create-react-app实用程序创建的React中使用'CORS'节点模块.
由于它是一个实用程序,我无法调整内部并将'CORS'注入预先配置的'EXPRESS'模块.
我们怎样才能做到这一点?
我今天用create-react-app创建了一个新项目.生产版本在IE11上运行不正常,控制台显示以下错误:
SCRIPT1010: Expected identifier
它指向我的main.js中的行:
{var n=e&&e.__esModule?function(){return e.default}:function(){return e};
错误发生在上面的e.(默认)之后.我的包json很简单:
{
"name": "sample-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我的开发服务器在IE11上完美运行所以问题只适用于生成版本.它也适用于Chrome.我需要填充吗?
polyfills internet-explorer-11 reactjs babeljs create-react-app
在一个文件中,我在以下行中导出包的所有类:
export {default as BoundList, IBoundListOption, TBoundListFilterFn} from './list/BoundList';
Run Code Online (Sandbox Code Playgroud)
生成表格错误:
TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided.
Run Code Online (Sandbox Code Playgroud)
我现在如何导出课程?
在CRA2.1中发生此问题。不得不强制执行isolatedModules = true。我正在CRA2.1上制作组件库
我有一个我无法解决的问题。我为所有项目在VSCode中使用ESLint。现在,我创建了一个新的react应用程序,但是当我运行它(npm start或yarn start)时,它会引发错误。
React应用使用ESLint 5.12.5,是我的较低版本。我尝试按照建议中的步骤进行操作,但...未解决。
谁能解决我的问题?
我试过npm uninstall -g eslint,npm uninstall eslint,npm i... bla..bla,打消了我的ESLint扩展在我VSCode,并重新创建应用程序的反应。但是错误尚未修复。
我检查了eslint -v,它表示为5.14.1,但是在错误通知中,vscode表示版本5.16.0在节点模块@@中。
当我尝试yarn start或时,这是完整的错误通知npm start:
> homework02@0.1.0 start E:\Extenal Code\Hoc JS\ReactJS-iViettech\homework02
> react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"eslint": "5.12.0"
Don't try …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个反应应用程序,我必须使用多个图像,现在我必须导入我将使用的每个图像,例如:
import image from '/img/img1.png';
<img src={img} />
Run Code Online (Sandbox Code Playgroud)
或者还有其他方法吗???,
PS:我尝试过“require”,它也给出了一个错误:
<img src={windows.location.origin +'/img/img1.png'}/>
Run Code Online (Sandbox Code Playgroud)
没有输出
我正在尝试加载要在构建时加载的 markdown 文件。我已经设置了一个使用 Typescript 并使用material_ui博客主题的create-react-app。
import ReactMarkdown from 'markdown-to-jsx';
import post1 from './blog-post.1.md';
export default function Main(props: MainProps) {
const classes = useStyles();
const { posts, title } = props;
return (
<Grid item xs={12} md={8}>
<Typography variant="h6" gutterBottom>
{title}
</Typography>
<Divider />
{posts.map((post) => (
<Markdown className={classes.markdown} key={post.substring(0, 40)}>
{post}
</Markdown>
))}
</Grid>
);
}
Run Code Online (Sandbox Code Playgroud)
如果帖子被指定为 markdown,它将正确呈现:const post = '# Sample blog post #### April 1, 2020 by [Olivier](/)'
所以问题是 .md 文件没有加载到变量中。
运行时npm start,html …
我已经使用设置了一个新项目npx create-react-app my-app --template typescript,并且没有更改任何配置设置。
如果我输入一些存在 TS 错误的代码,我的 IDE(VS Code)将显示该错误。但是,当我运行 start/build 时,我没有收到任何编译错误。
除此之外,npm run build在我们的 GitLab CI/CD 管道上运行时,确实会失败并出现错误。
我检查了我的 TS 版本,无论是在项目中还是我的全局模块所在的位置,都是相同的版本(4.1.3)。
正如我所说,我没有对 create React app 生成的内容进行任何更改,并且我尝试创建一个新项目并获得相同的结果。有人有什么想法吗?
编辑 - 要添加到这一点,如果我tsc在根目录运行,我会收到编译错误,但npm start我不会。
编辑 2 - 这是我在 package.json 中的脚本(与 CRA 提供给我们的内容相同)
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
Run Code Online (Sandbox Code Playgroud) 根据本文档,我在根目录中创建了一个 jsconfig.json 文件,以便能够在我的 React 应用程序(使用 create-react-app 设置)中使用绝对路径导入组件。不幸的是这不起作用。我尝试安装react-app-rewired 和react-app-rewire-alias 来尝试相同的操作,但没有成功。任何帮助,将不胜感激。
以下是我的 jsconfig.json 文件:
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Run Code Online (Sandbox Code Playgroud)
以及引发错误的文件(src/Components/Pages/Login/LoginForm)
import React from 'react'
import './Login.css'
import ToggleButton from '@material-ui/lab/ToggleButton'
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'
import IconButton from '@material-ui/core/IconButton'
import Button from '@material-ui/core/Button'
import Input from '@material-ui/core/Input'
import OutlinedInput from '@material-ui/core/OutlinedInput'
import InputLabel from '@material-ui/core/InputLabel'
import InputAdornment from '@material-ui/core/InputAdornment'
import FormControl from '@material-ui/core/FormControl'
import TextField from '@material-ui/core/TextField'
import {MdVisibility, MdVisibilityOff} from 'react-icons/md'
import { FormHelperText } from '@material-ui/core'
import …Run Code Online (Sandbox Code Playgroud) create-react-app ×10
reactjs ×9
typescript ×3
babeljs ×2
javascript ×2
antd ×1
cors ×1
eslint ×1
express ×1
jsx ×1
markdown ×1
npm ×1
polyfills ×1
redux ×1
semantic-ui ×1
webpack ×1