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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何修復(fù) TypeError:this.props.changeCategory 不是

如何修復(fù) TypeError:this.props.changeCategory 不是

qq_遁去的一_1 2022-07-15 09:28:56
我在代碼 Sandbox IDE 中工作,組件 ProductList 有問(wèn)題,我嘗試在 App.js 中添加函數(shù)。我在組件 ProductList 中將函數(shù)作為道具傳遞,但出現(xiàn)錯(cuò)誤,顯示 TypeError:this.props.changeCategory is not a function。我將代碼編寫(xiě)為“ onClick={() => this.props.changeCategory(category)}”我在 App.js 中將這個(gè)函數(shù)描述為changeCategory = category => {    this.setState({ currentCategory: category.categoryName });  };我的錯(cuò)誤信息:    TypeError_this2.props.changeCategory is not a functiononClick/src/components/ProductList.js:21:40  18 | <ListGroup>  19 |   {this.state.categories.map(category => (  20 |     <ListGroupItem> 21 |       onClick={() => this.props.changeCategory(category)}     |                                ^  22 |       key={category.categoryId}  23 |     >  24 |       {" "}產(chǎn)品列表.jsimport React, { Component } from "react";import { ListGroup, ListGroupItem } from "reactstrap";import "../styles.css";class ProductList extends Component {  state = {    categories: [      { categoryId: 1, categoryName: "Beverages" },      { categoryId: 2, categoryName: "Sunny Side UP" },      { categoryId: 3, categoryName: "Whats sup" }    ]  };  render() {    return (      <div>        <h3> {this.props.uc} </h3>        <ListGroup>          {this.state.categories.map(category => (            <ListGroupItem              onClick={() => this.props.changeCategory(category)}              key={category.categoryId}            >              {" "}              {category.categoryName}{" "}            </ListGroupItem>          ))}        </ListGroup>        <form className="f">{this.props.currentCategory}</form>      </div>    );  }}
查看完整描述

2 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

您沒(méi)有將函數(shù) changeCategory 從 App.js 傳遞給 ProductList。要將函數(shù)作為道具傳遞,您應(yīng)該在 App.js 文件中編寫(xiě)如下內(nèi)容,但您傳遞的是狀態(tài)值。

<pl changeCategory ={this.changeCategory} />


查看完整回答
反對(duì) 回復(fù) 2022-07-15
?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

您在 App.js 中將錯(cuò)誤的數(shù)據(jù)傳遞給產(chǎn)品列表組件的 changeCategory 道具。您必須為此道具提供功能參考。

 <Pl uc={titleCategory} changeCategory={this.changeCategory} />


查看完整回答
反對(duì) 回復(fù) 2022-07-15
  • 2 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

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