我正在尝试将一个函数传递给一个子组件,该函数将触发逻辑,在按下按钮后在我的网页上显示一个简单的文本表单,但我收到错误消息:
类型错误:this.props.changeFormStatus 不是函数
下面是父组件的代码:
import React from 'react';
import ReactDom from 'react-dom';
import RenderIcon from "./RenderIcon";
import RenderForm from "./RenderForm";
class RetroColumn extends React.Component {
constructor(props) {
super(props);
this.state = {formStatus:false};
this.changeFormStatus = this.changeFormStatus.bind(this);
}
changeFormStatus() {
this.setState({formStatus:true});
}
render() {
return (
<div className="column">
<div className="ui segment">
<h1 className="ui header">
<RenderIcon iconName="minus" iconMeaning="Remove"/>
{this.props.columnName}
<RenderIcon iconName="plus" whenUserClicks={this.changeFormStatus} iconMeaning="Add"/>
</h1>
<RenderForm revealForm={this.state.formStatus}/>
</div>
</div>
);
}
};
export default RetroColumn;
这是子组件的代码:
import React from 'react';
import ReactDom from 'react-dom';
class RenderIcon extends React.Component{
constructor(props){
super(props);
}
whenUserClicks() {
console.log(this.props);
this.props.changeFormStatus();
};
render() {
return (
<div className="ui vertical animated button" tabIndex="0" onClick={this.whenUserClicks()}>
<div className="hidden content">{this.props.iconMeaning}</div>
<div className="visible content">
<i className={`${this.props.iconName} icon`}></i>
</div>
</div>
);
}
}
export default RenderIcon;
繁星淼淼
相关分类