Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @ts-types="@types/react"
import * as React from 'react';
// @ts-types="@types/react-dom"
import * as ReactDOM from 'react-dom';

import App from './app';
Expand Down
26 changes: 26 additions & 0 deletions jsr.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@bureaudouble-forks/use-callback-ref",
"version": "1.3.2-forks.1",
"nodeModulesDir": false,
"compilerOptions": {
"noErrorTruncation": true,
"lib": [
"dom",
"dom.iterable",
"dom.asynciterable",
"deno.ns"
]
},
"imports": {
"@types/react": "npm:types-react@^19.0.0-rc",
"@types/react-dom": "npm:types-react-dom@^19.0.0-rc",
"react": "npm:react@^19.0.0-rc",
"react-dom": "npm:react@^19.0.0-rc",
"react-style-singleton": "jsr:@bureaudouble-forks/react-style-singleton@0.0.2",
"react-remove-scroll-bar": "jsr:@bureaudouble-forks/react-remove-scroll-bar@0.0.3"
},
"exports": {
".": "./src/index.ts"
}
}

2 changes: 1 addition & 1 deletion src/assignRef.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactRef } from './types';
import { ReactRef } from './types.ts';

/**
* Assigns a value for a given ref, no matter of the ref format
Expand Down
3 changes: 2 additions & 1 deletion src/createRef.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-types="@types/react"
import { RefObject } from 'react';

/**
Expand All @@ -8,7 +9,7 @@ import { RefObject } from 'react';
* @see {@link useCallbackRef}
* @see https://reactjs.org/docs/refs-and-the-dom.html#creating-refs
*/
export function createCallbackRef<T>(callback: (newValue: T | null, lastValue: T | null) => any): RefObject<T> {
export function createCallbackRef<T>(callback: (newValue: T | null, lastValue: T | null) => any): RefObject<T | null> {
let current: T | null = null;

return {
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export { assignRef } from './assignRef';
export { assignRef } from './assignRef.ts';

// callback ref
export { useCallbackRef } from './useRef';
export { createCallbackRef } from './createRef';
export { useCallbackRef } from './useRef.ts';
export { createCallbackRef } from './createRef.ts';

// merge ref
export { mergeRefs } from './mergeRef';
export { useMergeRefs } from './useMergeRef';
export { mergeRefs } from './mergeRef.ts';
export { useMergeRefs } from './useMergeRef.ts';

// transform ref
export { useTransformRef } from './useTransformRef';
export { transformRef } from './transformRef';
export { useTransformRef } from './useTransformRef.ts';
export { transformRef } from './transformRef.ts';

// refToCallback
export { refToCallback, useRefToCallback } from './refToCallback';
export { refToCallback, useRefToCallback } from './refToCallback.ts';
7 changes: 4 additions & 3 deletions src/mergeRef.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-types="@types/react"
import { MutableRefObject } from 'react';

import { assignRef } from './assignRef';
import { createCallbackRef } from './createRef';
import { ReactRef } from './types';
import { assignRef } from './assignRef.ts';
import { createCallbackRef } from './createRef.ts';
import { ReactRef } from './types.ts';

/**
* Merges two or more refs together providing a single interface to set their value
Expand Down
2 changes: 1 addition & 1 deletion src/refToCallback.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DefinedReactRef, ReactRef, RefCallback } from './types';
import { DefinedReactRef, ReactRef, RefCallback } from './types.ts';

/**
* Unmemoized version of {@link useRefToCallback}
Expand Down
6 changes: 3 additions & 3 deletions src/transformRef.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assignRef } from './assignRef';
import { createCallbackRef } from './createRef';
import { ReactRef, RefObject } from './types';
import { assignRef } from './assignRef.ts';
import { createCallbackRef } from './createRef.ts';
import { ReactRef, RefObject } from './types.ts';

/**
* Transforms one ref to another
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-types="@types/react"
import * as React from 'react';

export type RefCallback<T> = (newValue: T | null) => void;
Expand Down
7 changes: 4 additions & 3 deletions src/useMergeRef.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @ts-types="@types/react"
import * as React from 'react';

import { assignRef } from './assignRef';
import { ReactRef } from './types';
import { useCallbackRef } from './useRef';
import { assignRef } from './assignRef.ts';
import { ReactRef } from './types.ts';
import { useCallbackRef } from './useRef.ts';

const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;

Expand Down
1 change: 1 addition & 0 deletions src/useRef.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-types="@types/react"
import { MutableRefObject, useState } from 'react';

/**
Expand Down
6 changes: 3 additions & 3 deletions src/useTransformRef.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assignRef } from './assignRef';
import { ReactRef, RefObject } from './types';
import { useCallbackRef } from './useRef';
import { assignRef } from './assignRef.ts';
import { ReactRef, RefObject } from './types.ts';
import { useCallbackRef } from './useRef.ts';

/**
* Create a _lense_ on Ref, making it possible to transform ref value
Expand Down