我试图创建一个手风琴风格的按钮,并设置我的组件与按钮功能来隐藏我的列表点击,但我列表不会再出现,并且还想添加隐藏/显示列表之间的动画过渡。我应该在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>
);
}
}
我更新了我的答案以解决您的问题。 –