I'm trying to create an accordion style button and have setup my component with the button functionality to hide my list on click, but I the list does not reappear and would also like to add an animated transition between hiding/showing the list. Should I be using prevState in my handleClick() function? Is there a preferred method for handling the animation? React? 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>
);
}
}