[英]Module build failed (from ./node_modules/babel-loader/lib/index.js)
I have this code on my App.js:我的 App.js 上有这段代码:
import React, {useEffect, useState} from 'react'
function App() {
const [backendData, setBackendData] = useState([{}])
useEffect(() => {
fetch("/api").then(response => response.json()).then(
data => {
setBackendData(data)
}
)
}, [])
return (
<div>
{(typeof backendData.users === 'undefined') ? (
<p>Loading...</p>
): (
backendData.users.map(user, i) => (
<p key={i}>
{user}
</p>
))
)}
</div>
)
}
export default App
And i keep receiving this error:我一直收到这个错误:
ERROR in ./src/App.js ./src/App.js 中的错误
Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: E:\Interconnect\client\src\App.js: Unexpected token, expected "," (19:39)模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):SyntaxError: E:\Interconnect\client\src\App.js: Unexpected token, expected "," (19:39)
THE LINE 19 is this one:第 19 行是这样的:
backendData.users.map(user, i) => (
The correct syntax is正确的语法是
backendData.users.map((user, i) => (
<p key={i}>
{user}
</p>
))
with a pair of parentheses around the (user, i) => (...)
function.在
(user, i) => (...)
函数周围有一对括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.