【发布时间】:2018-03-29 18:57:09
【问题描述】:
我正在尝试创建一个手风琴风格的按钮,并设置我的组件具有按钮功能以在单击时隐藏我的列表,但我的列表没有重新出现,并且还想在隐藏/显示之间添加动画过渡列表。我应该在我的handleClick() 函数中使用prevState 吗?是否有处理动画的首选方法?反应? CSS?
//Render Links
const ReportLinks = props => {
return (
<ul>
{
props.links.map((link, index) => {
return ( <li key={index}><a href={link.reportLink}>{link.reportLink}</a></li> )
})
}
</ul>
)
}
class Footer extends React.Component {
constructor(props){
super(props);
this.state = { linksHidden: true };
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
this.setState({ linksHidden: false });
}
render() {
return (
<div className="annotation-card__footer">
<button onClick={this.handleClick}>Report Links ({this.props.report.length})</button>
{ this.state.linksHidden ? <ReportLinks links={this.props.report}/> : null }
</div>
);
}
}
【问题讨论】:
-
我更新了我的答案来解决你的问题。
标签: javascript reactjs state