Skip to content

Commit

Permalink
Merge branch 'main' into fix-benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Mar 18, 2024
2 parents 1385d37 + a2c12f5 commit 171fd19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 8 additions & 4 deletions hooks/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ import { ErrorInfo, PreactContext, Ref as PreactRef } from '../..';

type Inputs = ReadonlyArray<unknown>;

export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
export type Dispatch<A> = (value: A) => void;
export type StateUpdater<S> = 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<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
export function useState<S>(
initialState: S | (() => S)
): [S, Dispatch<StateUpdater<S>>];

export function useState<S = undefined>(): [
S | undefined,
StateUpdater<S | undefined>
Dispatch<StateUpdater<S | undefined>>
];

export type Reducer<S, A> = (prevState: S, action: A) => S;
export type Dispatch<A> = (action: A) => void;

/**
* An alternative to `useState`.
*
Expand Down
4 changes: 2 additions & 2 deletions hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function getHookState(index, type) {

/**
* @template {unknown} S
* @param {import('./index').StateUpdater<S>} [initialState]
* @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} [initialState]
* @returns {[S, (state: S) => void]}
*/
export function useState(initialState) {
Expand All @@ -179,7 +179,7 @@ export function useState(initialState) {
* @template {unknown} S
* @template {unknown} A
* @param {import('./index').Reducer<S, A>} reducer
* @param {import('./index').StateUpdater<S>} initialState
* @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} initialState
* @param {(initialState: any) => void} [init]
* @returns {[ S, (state: S) => void ]}
*/
Expand Down
9 changes: 5 additions & 4 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,10 +1563,10 @@ export namespace JSXInternal {
// Focus Events
onFocus?: FocusEventHandler<Target> | undefined;
onFocusCapture?: FocusEventHandler<Target> | undefined;
onfocusin?: FocusEventHandler<Target> | undefined;
onfocusinCapture?: FocusEventHandler<Target> | undefined;
onfocusout?: FocusEventHandler<Target> | undefined;
onfocusoutCapture?: FocusEventHandler<Target> | undefined;
onFocusIn?: FocusEventHandler<Target> | undefined;
onFocusInCapture?: FocusEventHandler<Target> | undefined;
onFocusOut?: FocusEventHandler<Target> | undefined;
onFocusOutCapture?: FocusEventHandler<Target> | undefined;
onBlur?: FocusEventHandler<Target> | undefined;
onBlurCapture?: FocusEventHandler<Target> | undefined;

Expand Down Expand Up @@ -1718,6 +1718,7 @@ export namespace JSXInternal {

// UI Events
onScroll?: UIEventHandler<Target> | undefined;
onScrollEnd?: UIEventHandler<Target> | undefined;
onScrollCapture?: UIEventHandler<Target> | undefined;

// Wheel Events
Expand Down

0 comments on commit 171fd19

Please sign in to comment.