function component
React
関数で記述されたコンポーネントのこと
以前はStateless Functional Component (SFC) と呼ばれていた
React Hooksの登場により状態を持てるようになったので, 単にfunction componentと呼ばれるようになった
参考
https://github.com/reactjs/reactjs.org/pull/863
https://github.com/reactjs/reactjs.org/pull/1628
code:tsx
interface Props {
defaultCount: number
}
functioin Counter(props: Props) {
const count, setCount = React.useState(props.defaultCount)
function handleClick() {
setCount((count) => count + 1)
}
return <button onClick={handleClick}>{count}</button>
}