第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ReactJS:解析錯誤:意外的令牌,預期的“}”

ReactJS:解析錯誤:意外的令牌,預期的“}”

慕桂英546537 2022-07-08 10:27:52
我正在開發(fā)一個 React 應用程序,我正在使用 Redux 來存儲狀態(tài)。我有以下代碼:import React, { Component } from 'react';import { connect } from 'react-redux';import { increaseCategoryRank, decreaseCategoryRank } from '../../redux/menu/menu.actions';import './category-arrows.styles.scss';class CategoryArrows extends Component {    render() {        const { category } = this.props;        const categoryClicked = true;        const initialRank = category.rank;        return (            <div className="arrows-container">                <div className="up-arrow" onClick={                    (initialRank) =>                    this.props.increaseCategoryRank(category, categoryClicked)                    if(initialRank === -1) {                        this.props.menu.map(menuCategory => menuCategory._id !== category._id ? this.props.increaseCategoryRank(menuCategory, !categoryClicked) : null)                    } else {                        return null;                    }                }></div>                <div className="category-rank">                    <p>{category.rank}</p>                </div>                <div className="down-arrow" onClick={() => this.props.decreaseCategoryRank(category,  categoryClicked)}></div>            </div>        )    }}const mapStateToProps = state => ({    menu: state.menu})export default connect(mapStateToProps, { increaseCategoryRank, decreaseCategoryRank } )(CategoryArrows);單擊 div時up-arrow,我正在調(diào)用一個函數(shù)。但是,我收到以下錯誤:我不確定為什么會收到此錯誤或如何解決此錯誤。任何見解都值得贊賞。
查看完整描述

1 回答

?
繁星coding

TA貢獻1797條經(jīng)驗 獲得超4個贊

看起來你有一個懸而未決的if聲明。在箭頭函數(shù)中使用大括號,或者使用三元表達式。


onClick={(initialRank) => { //<-- add brace bracket

    this.props.increaseCategoryRank(category, categoryClicked)

    //with no brace brackets, function would end on the line above. 

    //The rest is dangling, hence the error

    if(initialRank === -1) {

        this.props.menu.map(menuCategory => menuCategory._id !== category._id ? this.props.increaseCategoryRank(menuCategory, !categoryClicked) : null)


    } else {

        return null;

    }

}}


查看完整回答
反對 回復 2022-07-08
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號