我只是试图检查一个条件(invitesForEvent.length)并在vitatesForEvent上运行一个映射循环,但是却收到如下所示的错误:
我只是试图检查一个条件(invitesForEvent.length)并在vitatesForEvent上运行一个映射循环,但是却收到如下所示的错误:
./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>
))
}
)
}
}
导出默认邀请;
答案 0 :(得分:0)
您当时正在切换逻辑。使用片段或直接返回:
return (<>
{invitesForEvent.length <= 0
? 'NO ENTRIES YET'
: invitesForE
或使用这种方式:
return invitesForEvent.length <= 0
? 'NO ENTRIES YET'
: invitesForEvent.map((dat) => (
<div>Event invite entry: {invitesForEvent.length}</div>
))