Skip to content

Commit

Permalink
Merge branch 'main' into consistency-focus-events
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Mar 17, 2024
2 parents 53ea464 + cfba5ee commit 06a4bbb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 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
1 change: 1 addition & 0 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
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 06a4bbb

Please sign in to comment.