简体   繁体   English

如何解决这个 期望赋值或函数调用,而是看到一个表达式 no-unused-expressions

[英]how to solve this Expected an assignment or function call and instead saw an expression no-unused-expressions

problem :问题 :

./src/components/main.js Line 7: Expected an assignment or function call and instead saw an expression no-unused-expressions ./src/components/main.js 第 7 行:期望赋值或函数调用,但看到的是表达式 no-unused-expressions

Search for the keywords to learn more about each error.搜索关键字以了解有关每个错误的更多信息。

import React from 'react';
import { Switch, Route } from 'react-router-dom';
import LandingPage from './landingpage'

const Main = () => {
   <Switch>
      <Route exact path="/" component={LandingPage}/>
   </Switch>
}

export default Main;

how can i solve this, please help me我该如何解决这个问题,请帮帮我

You're missing a couple of things.你错过了几件事。 First you need to import BrowserRouter or Router from react-router-dom .首先,您需要从react-router-dom导入BrowserRouterRouter And you need to return your Router.你需要归还你的路由器。

import React from 'react';
import { Switch, Route, BrowserRouter } from 'react-router-dom';
import LandingPage from './landingpage'

const Main = () => {
   return(
     <BrowserRouter>
       <Switch>
         <Route exact path="/" component={LandingPage}/>
       </Switch>
     </BrowserRouter/>
   )
}

export default Main;

Just Change Bracket Braces To parenthesis.只需将括号大括号更改为括号即可。 when you write JSX inside the function you need to use parenthesis not Bracket because your function has JSX.当您在函数内部编写 JSX 时,您需要使用括号而不是 Bracket,因为您的函数具有 JSX。 {}=>() {}=>()

import React from 'react';
import { Switch, Route } from 'react-router-dom';
import LandingPage from './landingpage'

const Main = () => (
   <Switch>
      <Route exact path="/" component={LandingPage}/>
   </Switch>
)

export default Main

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预期分配或 function 调用,而是看到一个表达式 no-unused-expressions - 如何修复此 CI 错误? - Expected an assignment or function call and instead saw an expression no-unused-expressions - how to fix this CI error? 得到预期赋值或函数调用的错误,而是看到一个表达式 no-unused-expressions? - Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions? 得到预期的赋值或函数调用的错误,而是在反应中看到了一个表达式 no-unused-expressions - getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react 期望一个赋值或函数调用,而是在React中看到一个表达式no-unused-expressions错误 - Expected an assignment or function call and instead saw an expression no-unused-expressions error in React Object.keys-需要一个赋值或函数调用,而是看到一个表达式no-unused-expressions - Object.keys - Expected an assignment or function call and instead saw an expression no-unused-expressions 重定向(反应路由器dom),给出了期望的赋值或函数调用,而是看到了一个表达式no-unused-expressions - Redirect (react router dom) giving Expected an assignment or function call and instead saw an expression no-unused-expressions “预期分配或 function 调用,而是在我的聊天应用程序中看到一个表达式 no-unused-expressions” - “Expected an assignment or function call and instead saw an expression no-unused-expressions” in my chat app 第 55:11 行:期望一个赋值或 function 调用,而是看到一个表达式 no-unused-expressions - Line 55:11: Expected an assignment or function call and instead saw an expression no-unused-expressions 在React中导入文件时,获得期望的赋值或函数调用,而是看到一个表达式no-unused-expressions - Getting Expected an assignment or function call and instead saw an expression no-unused-expressions, when import a file in React 反应:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions - React: expected an assignment or function call and instead saw an expression no-unused-expressions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM