I am trying to write a react class where the render function contains a button which once clicked, it changes the css class from one to another as well as changes the text from available to taken. The text change is working but not the CSS change. I am not sure where I am going wrong in my code below. I also tried to write a toggle class function in my class methods which isn't switching as well. Not too strong in html and JSX so any help would be appreciated. Thanks.
class Singles extends React.Component {
constructor() {
super();
this.state = {
isSingle: false,
};
}
toggleIsSingle() {
this.setState({
isSingle: !this.state.isSingle
});
}
render() {
const { name, description, id } = this.props.pet;
const isSingle = this.state.isSingle;
return (
<div
key={id}
className={this.state.isSingle ? 'single.taken' : 'single'}
>
<div id="info">
<p>{name}</p>
<p>{description}</p>
<div>{this.state.isSingle ? 'Taken!' : 'Available'}</div>
<button onClick={() => this.toggleIsSingle()}>Toggle Status</button>
</div>
</div>
);
}
}