[英]Javascript Uncaught TypeError: AccountID is not a function
[英]React - TypeError: this.props.AccountId is not a function
我已經對這個問題進行了研究,但我似乎無法找到解決我的問題的方法。
同一問題的其他帖子似乎與綁定問題有關,但我認為這不是問題所在。
當我加載頁面時,應該顯示道具,但它不顯示任何內容。
當我以文本形式書寫時,出現錯誤:TypeError: this.props.AccountId is not a function”,這就是我被困的地方。
import React from 'react';
class Accountparent extends React.Component {
constructor(props) {
super(props);
this.onFocusChange = this.onFocusChange.bind(this);
this.state = {accountobj: ''};
}
onFocusChange(value){
this.setState({accountobj: value});
}
render() {
return (
<div>
<Account value={this.state.accountobj} AccountId={this.onFocusChange}/>
</div>
)
}
}
class Account extends React.Component {
constructor(props) {
super(props);
this.EditAccount = this.EditAccount.bind(this)
this.state = {
accounts: [],
};
}
EditAccount(e){
this.props.AccountId(e.target.value)
}
render() {
const value = this.props.AccountId;
return (
<div>
<div>The props is: {this.props.dataid}</div>
<div>Write to textfield to pass data to parent: <input value={value} type="text" onChange={this.EditAccount}/></div>
</div>
)
}
}
export default Account;
編輯:正如@Taki 所建議的,我應該導出父級。 這就是解決方案
檢查你的代碼,
EditAccount(e){
this.props.AccountId(e.target.value)
}
render() {
const value = this.props.AccountId;
. . .
在 EditAccount 方法中,您可以像使用函數一樣使用它。 在渲染方法中,您從中獲得“價值”。 它可以是一個值或一個函數。 不是都。
正如@Taki 建議的那樣,我應該導出父級。 這就是解決方案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.