Skip to content

Instantly share code, notes, and snippets.

@alirezamirian
Last active February 22, 2019 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezamirian/c832c40dc1800a56d409cada73b50791 to your computer and use it in GitHub Desktop.
Save alirezamirian/c832c40dc1800a56d409cada73b50791 to your computer and use it in GitHub Desktop.
For medium post
interface UsageProps {
value?: number;
changeHandler?: (value: number) => number | void;
}
function Counter({value, changeHandler}: UsageProps) {
const [valueState, setValue] = useControllableState(value, changeHandler, 0);
return <div>
<span className="value">{valueState}</span>
<button className="btn" onClick={() => setValue(valueState + 1)}>Increase</button>
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment