From 74dbf4c46a27e9017f5484a785246950f0856863 Mon Sep 17 00:00:00 2001 From: oyar Date: Sun, 30 Oct 2022 10:39:33 +0000 Subject: [PATCH] feat: add types to keyboard controls (#1118) * feat: add types to keyboard controls * docs: keyboard controls update * fix: keyboard control types * fix: typo --- README.md | 4 ++-- src/web/KeyboardControls.tsx | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 710870e42..584e15ee8 100644 --- a/README.md +++ b/README.md @@ -353,7 +353,7 @@ Scroll controls create a HTML scroll container in front of the canvas. Everythin You can listen and react to scroll with the `useScroll` hook which gives you useful data like the current scroll `offset`, `delta` and functions for range finding: `range`, `curve` and `visible`. The latter functions are especially useful if you want to react to the scroll offset, for instance if you wanted to fade things in and out if they are in or out of view. ```jsx - } -export function useKeyboardControls(): [ +type Selector = (state: KeyboardControlsState) => boolean + +export function useKeyboardControls(): [ Subscribe>, GetState> ] -export function useKeyboardControls( - sel: StateSelector, U> -): U -export function useKeyboardControls( - sel?: StateSelector, U> -): U | [Subscribe>, GetState>] { +export function useKeyboardControls(sel: Selector): ReturnType> +export function useKeyboardControls( + sel?: Selector +): ReturnType> | [Subscribe>, GetState>] { const [sub, get, store] = React.useContext>(context) if (sel) return store(sel) else return [sub, get]