reactjs - React Route - cannot assign to "render" because it is not a variable
问题描述
Here's a PrivateRoute I'm trying to make
function PrivateRoute({ component: Component, ...rest }) {
return <Route {...rest} render={(props) => <Component {...props} />} />
}
At Route
and {...rest}
, eslint throws Parsing error: > expected
.
At render=
, I get Cannot assign to 'render' because it is not a variable
and for every other identifier after it, I get unreachable code
.
What am I missing?
解决方案
First and foremost, All React component names must start with a capital
letter. If you start a component name with a lowercase letter, it will be treated like a built-in element like a <div>
or a <span>
. This is because of the way JSX works.
Try to disable eslint in this file because I think eslint has been confused.
Add the below comment at top of your file.
/* eslint-disable */
推荐阅读
- c# - 附加 DLL 后,Windows 程序无法在另一台计算机上运行
- powershell - Powershell 替换 Unicode 字符,如“çöşİğü”
- docker - 有没有办法设置多个本地 Go 模块,这样它们就可以在一个 Docker 容器中运行而无需从 Github 中提取?
- angular - 使用 ngx-translate 为每种语言使用多个 JSON 进行翻译
- discord.js - 如何制作邀请命令,根据成员是否仍在服务器中进行更新
- javascript - 数字总和,更清晰的 JS 版本
- c# - 如何以编程方式在 wpf 应用程序中添加元素
- performance - Imagemagick 转换超慢
- javascript - 如何在 Vue 中使用渲染函数使 DOM 反应?
- c# - TcpClient - 并非所有数据都被客户端接收