Skip to content

Commit

Permalink
Merge pull request #3056 from cmlenz/master
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 15, 2021
2 parents bd0942f + 1a337a8 commit 4e29ec7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compat/test/ts/forward-ref.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from '../../src';

const MyInput: React.ForwardFn<{ id: string }, { focus(): void }> = (props, ref) => {
const inputRef = React.useRef<HTMLInputElement>()
const inputRef = React.useRef<HTMLInputElement>(null)

React.useImperativeHandle(ref, () => ({
focus: () => {
Expand Down
16 changes: 7 additions & 9 deletions hooks/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PreactContext, Ref as PreactRef } from '../..';
import { PreactContext, Ref as PreactRef, RefObject } from '../..';

type Inputs = ReadonlyArray<unknown>;

Expand Down Expand Up @@ -40,6 +40,7 @@ export function useReducer<S, A, I>(
init: (arg: I) => S
): [S, (action: A) => void];

/** @deprecated Use the `Ref` type instead. */
type PropRef<T> = { current: T };
type Ref<T> = { current: T };

Expand All @@ -49,15 +50,12 @@ type Ref<T> = { current: T };
*
* Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
* value around similar to how you’d use instance fields in classes.
*
* @param initialValue the initial value to store in the ref object
*/
export function useRef<T>(initialValue?: T | null): Ref<T>;

/**
* `useRef` without an initial value is the special case handling `ref` props.
* If you want a non prop-based, mutable ref, you can explicitly give it an initial value of undefined/null/etc.
* You should explicitly set the type parameter for the expected ref value to either a DOM Element like `HTMLInputElement` or a `Component`
*/
export function useRef<T = unknown>(): PropRef<T>;
export function useRef<T>(initialValue: null): RefObject<T>;
export function useRef<T>(initialValue: T): Ref<T>;
export function useRef<T>(): Ref<T | undefined>;

type EffectCallback = () => void | (() => void);
/**
Expand Down

0 comments on commit 4e29ec7

Please sign in to comment.