From f8a080180b3b71d4229e09eb2e2df5e7d683ffd3 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sun, 17 Mar 2024 19:32:06 +0100 Subject: [PATCH 1/3] align state updater type (#4306) --- hooks/src/index.d.ts | 12 ++++++++---- hooks/src/index.js | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hooks/src/index.d.ts b/hooks/src/index.d.ts index 561f034943..3ec8999ca6 100644 --- a/hooks/src/index.d.ts +++ b/hooks/src/index.d.ts @@ -2,20 +2,24 @@ import { ErrorInfo, PreactContext, Ref as PreactRef } from '../..'; type Inputs = ReadonlyArray; -export type StateUpdater = (value: S | ((prevState: S) => S)) => void; +export type Dispatch = (value: A) => void; +export type StateUpdater = S | ((prevState: S) => S); + /** * Returns a stateful value, and a function to update it. * @param initialState The initial value (or a function that returns the initial value) */ -export function useState(initialState: S | (() => S)): [S, StateUpdater]; +export function useState( + initialState: S | (() => S) +): [S, Dispatch>]; export function useState(): [ S | undefined, - StateUpdater + Dispatch> ]; export type Reducer = (prevState: S, action: A) => S; -export type Dispatch = (action: A) => void; + /** * An alternative to `useState`. * diff --git a/hooks/src/index.js b/hooks/src/index.js index f2a0c12922..094410d7a3 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -167,7 +167,7 @@ function getHookState(index, type) { /** * @template {unknown} S - * @param {import('./index').StateUpdater} [initialState] + * @param {import('./index').Dispatch>} [initialState] * @returns {[S, (state: S) => void]} */ export function useState(initialState) { @@ -179,7 +179,7 @@ export function useState(initialState) { * @template {unknown} S * @template {unknown} A * @param {import('./index').Reducer} reducer - * @param {import('./index').StateUpdater} initialState + * @param {import('./index').Dispatch>} initialState * @param {(initialState: any) => void} [init] * @returns {[ S, (state: S) => void ]} */ From cfba5eef8e4072f6d01594386b34b8902d3c6ada Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sun, 17 Mar 2024 19:39:00 +0100 Subject: [PATCH 2/3] add onscrollend listener type (#4305) --- src/jsx.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index c58ac48e69..24aa73beae 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1718,6 +1718,7 @@ export namespace JSXInternal { // UI Events onScroll?: UIEventHandler | undefined; + onScrollEnd?: UIEventHandler | undefined; onScrollCapture?: UIEventHandler | undefined; // Wheel Events From a2c12f5a46a70b2b58517f5e14e731a77d6d64a3 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sun, 17 Mar 2024 19:40:38 +0100 Subject: [PATCH 3/3] bring consistency to our focus events (#4307) --- src/jsx.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 24aa73beae..2accfbac89 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1563,10 +1563,10 @@ export namespace JSXInternal { // Focus Events onFocus?: FocusEventHandler | undefined; onFocusCapture?: FocusEventHandler | undefined; - onfocusin?: FocusEventHandler | undefined; - onfocusinCapture?: FocusEventHandler | undefined; - onfocusout?: FocusEventHandler | undefined; - onfocusoutCapture?: FocusEventHandler | undefined; + onFocusIn?: FocusEventHandler | undefined; + onFocusInCapture?: FocusEventHandler | undefined; + onFocusOut?: FocusEventHandler | undefined; + onFocusOutCapture?: FocusEventHandler | undefined; onBlur?: FocusEventHandler | undefined; onBlurCapture?: FocusEventHandler | undefined;