[英]React: Parsing error: Unexpected token, expected “,”
I am merely trying to check a condition (invitesForEvent.length) and run a map loop on invitesForEvent, but am getting the error shown below:我只是想检查一个条件(invitesForEvent.length)并在invitesForEvent上运行一个map循环,但我得到了如下所示的错误:
I am merely trying to check a condition (invitesForEvent.length) and run a map loop on invitesForEvent, but am getting the error shown below:我只是想检查一个条件(invitesForEvent.length)并在invitesForEvent上运行一个map循环,但我得到了如下所示的错误:
./src/Invites.js
Line 36: Parsing error: Unexpected token, expected ","
34 | console.log("this.state.invitesForEventData.length: " +
this.state.invitesForEventData.length );
35 | return (
> 36 | {invitesForEvent.length <= 0
| ^
37 | ? 'NO ENTRIES YET'
38 | : invitesForEvent.map((dat) => (
39 | <div>Event invite entry: {invitesForEvent.length}</div>
import React from 'react';
import axios from 'axios';
import CSS from './css/styles.css';
class Invites extends React.Component {
state = {
invitesForEventData: [{test: []}]
}
componentDidMount() {
this.getInvitesForEvent(this.props.eventid);
}
getInvitesForEvent = (eventid) => {
console.log("eventid: " + eventid)
axios.post('http://localhost:3001/api/getInvitesForEvent', {
eventid: eventid
})
.then((response) => {
console.log("response.data.data: ", response);
this.setState({ invitesForEventData: response.data.data })
})
.catch(function (error) {
console.log(error);
});
};
render() {
const invitesForEvent = this.state.invitesForEventData;
console.log("this.state.invitesForEventData.length: " +
this.state.invitesForEventData.length );
return (
{invitesForEvent.length <= 0
? 'NO ENTRIES YET'
: invitesForEvent.map((dat) => (
<div>Event invite entry: {invitesForEvent.length}</div>
))
}
)
}
}
export default Invites;
You are switching the logic at that time.您当时正在切换逻辑。 Use a fragment or directly return:
使用片段或直接返回:
return (<>
{invitesForEvent.length <= 0
? 'NO ENTRIES YET'
: invitesForE
Or use this way:或者这样使用:
return invitesForEvent.length <= 0
? 'NO ENTRIES YET'
: invitesForEvent.map((dat) => (
<div>Event invite entry: {invitesForEvent.length}</div>
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.