![](/img/trans.png)
[英]Error: Expected an assignment or function call and instead saw an expression no-unused-expressions. How to solve it?
[英]Expected an assignment or function call and instead saw an expression : no unused expression
import Alert from '@material-ui/lab/Alert';
export default function MyComponent(props) {
let [disabled] = useState(false);
const calculateTotal = event => {
if (!disabled) {
disabled = true;
calTotal().then(validateResult => {
disabled = false;
});
} }
{ return(
disabled && (
<Alert severity="warning"> Previous request is in progress!!! </Alert>
)
)}
};
使用返回功能有效,但我一起丟失了警告消息
您需要將 JSX 傳遞給渲染引擎。 我整理了一個 例子:
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
const rootElement = document.getElementById("root");
// If I tried to execute this line it would fail (see the Problems tab)
<App />;
// But this works (because you need an engine to render JSX)
ReactDOM.render(<App />, rootElement);
如果在組件中渲染,則需要返回 JSX:
const Test = () => (
<Alert>My Alert</Alert>
)
// or more verbosely
const Test2 = () => {
return <Alert>My Alert</Alert>
}
希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.