From 299fd8646987ba3516ff5760a469bff46b8adae0 Mon Sep 17 00:00:00 2001 From: streamich Date: Thu, 28 Mar 2019 17:52:53 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20useKey=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__stories__/useKey.story.tsx | 31 ++++++++++++++++++++++++++++ src/index.ts | 2 ++ src/useEvent.ts | 1 - src/useKey.ts | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/__stories__/useKey.story.tsx create mode 100644 src/useKey.ts diff --git a/src/__stories__/useKey.story.tsx b/src/__stories__/useKey.story.tsx new file mode 100644 index 0000000000..1089d250ab --- /dev/null +++ b/src/__stories__/useKey.story.tsx @@ -0,0 +1,31 @@ +import { storiesOf } from "@storybook/react"; +import * as React from "react"; +import {useKey} from ".."; +import ShowDocs from "../util/ShowDocs"; +import {CenterStory} from "./util/CenterStory"; + +const Demo = () => { + const [count, setCount] = React.useState(0); + + const increment = () => setCount(count => ++count); + const decrement = () => setCount(count => --count); + const reset = () => setCount(count => 0); + + useKey(']', increment); + useKey('[', decrement); + useKey('r', reset); + + return ( + +