我試圖創建一個手風琴風格的按鈕,並設置我的組件與按鈕功能來隱藏我的列表點擊,但我列表不會再出現,並且還想添加隱藏/顯示列表之間的動畫過渡。我應該在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>
);
}
}
我更新了我的答案以解決您的問題。 –