mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
17 lines
379 B
JavaScript
17 lines
379 B
JavaScript
// @flow
|
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
type Props = {|
|
|
initialCount: number,
|
|
|};
|
|
|
|
export default function FunctionWithState({ initialCount }: Props) {
|
|
const [count, setCount] = useState(initialCount);
|
|
const handleClick = useCallback(() => {
|
|
setCount(count => count + 1);
|
|
});
|
|
|
|
return <button onClick={handleClick}>Count {count}</button>;
|
|
}
|