useState hooks (Functional Component)
Tue Dec 26 2023 22:23:19 GMT+0000 (Coordinated Universal Time)
Saved by
@Marcelluki
// the User functional component
function User(props) {
// the hook that manages internal state
const [rating, setRating] = React.useState(0);
/*
* event handlers to update internal state
*/
function handleLike() {
setRating(1);
}
function handleDislike() {
setRating(-1);
}
return (
<div className="user">
<img src={`img/${props.id}.png`} width="75" />
{props.name}
<div className="rating">
<button onClick={handleLike} disabled={rating > 0}>👍</button>
{rating}
<button onClick={handleDislike} disabled={rating < 0}>👎</button>
</div>
</div>
);
}
content_copyCOPY
https://tripleten.com/trainer/web/lesson/46460f66-7574-4d1b-a269-8e5c08776b78/
Comments