← React Beginner Questions - Set 6 Q60
React Beginner Questions - Set 6
A function that receives props and returns JSX. With hooks it holds state, effects and refs — the class distinction is historical.
import { useState } from 'react';
// Props in, JSX out; state comes from hooks
export default function LikeButton({ initial = 0 }) {
const [likes, setLikes] = useState(initial);
return (
<button onClick={() => setLikes(l => l + 1)} aria-pressed={likes > 0}>
♥ {likes}
</button>
);
}
// It is just a function: callable, composable, testable
// <LikeButton initial={5} />