Added basic toggle state to like component

This commit is contained in:
James Morris 2022-07-06 17:02:18 +02:00
parent ddd72eba98
commit c394037cab

View File

@ -1,9 +1,30 @@
import React from 'react';
import AppContext from '../AppContext';
import {ReactComponent as LikeIcon} from '../images/icons/like.svg';
function Like() {
return (
<button className="flex font-sans text-[14px] items-center"><LikeIcon className='gh-comments-icon gh-comments-icon-like mr-1' />3</button>
);
class Like extends React.Component {
static contextType = AppContext;
constructor(props) {
super(props);
this.state = {
liked: false
};
this.toggleLike = this.toggleLike.bind(this);
}
toggleLike() {
this.setState(state => ({
liked: !state.liked
}));
}
render() {
return (
<button className="flex font-sans text-[14px] items-center" onClick={this.toggleLike}><LikeIcon className={`gh-comments-icon gh-comments-icon-like mr-1 ${this.state.liked ? 'fill-black' : ''}`} />3</button>
);
}
}
export default Like;