mirror of
https://github.com/ragestudio/comty.git
synced 2025-07-08 16:54:15 +00:00
Refactor LikeButton to use named function component
This commit is contained in:
parent
843405dd15
commit
179baa3777
@ -4,7 +4,7 @@ import CountUp from "react-countup"
|
|||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
export default (props) => {
|
const LikeButtonAction = (props) => {
|
||||||
const [liked, setLiked] = React.useState(props.defaultLiked ?? false)
|
const [liked, setLiked] = React.useState(props.defaultLiked ?? false)
|
||||||
const [clicked, setCliked] = React.useState(false)
|
const [clicked, setCliked] = React.useState(false)
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ export default (props) => {
|
|||||||
|
|
||||||
if (typeof props.onClick === "function") {
|
if (typeof props.onClick === "function") {
|
||||||
const result = await props.onClick(to)
|
const result = await props.onClick(to)
|
||||||
|
|
||||||
if (typeof result === "boolean") {
|
if (typeof result === "boolean") {
|
||||||
to = result
|
to = result
|
||||||
}
|
}
|
||||||
@ -23,16 +24,12 @@ export default (props) => {
|
|||||||
setLiked(to)
|
setLiked(to)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div
|
return (
|
||||||
className={
|
<div
|
||||||
classnames(
|
className={classnames("like_btn_wrapper", {
|
||||||
"like_btn_wrapper",
|
|
||||||
{
|
|
||||||
["liked"]: liked,
|
["liked"]: liked,
|
||||||
["clicked"]: clicked
|
["clicked"]: clicked,
|
||||||
}
|
})}
|
||||||
)
|
|
||||||
}
|
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
>
|
>
|
||||||
<button className="like_btn">
|
<button className="like_btn">
|
||||||
@ -56,4 +53,7 @@ export default (props) => {
|
|||||||
useEasing={true}
|
useEasing={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default LikeButtonAction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user