@dxos/react-hooks 0.8.4-main.a4bbb77 → 0.8.4-main.ae835ea

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-hooks",
3
- "version": "0.8.4-main.a4bbb77",
3
+ "version": "0.8.4-main.ae835ea",
4
4
  "description": "React hooks supporting DXOS React primitives.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -28,13 +28,14 @@
28
28
  "@preact-signals/safe-react": "^0.9.0",
29
29
  "alea": "^1.0.1",
30
30
  "lodash.defaultsdeep": "^4.6.1",
31
- "@dxos/async": "0.8.4-main.a4bbb77",
32
- "@dxos/log": "0.8.4-main.a4bbb77"
31
+ "mini-virtual-list": "^0.3.2",
32
+ "@dxos/async": "0.8.4-main.ae835ea",
33
+ "@dxos/log": "0.8.4-main.ae835ea"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/lodash.defaultsdeep": "^4.6.6",
36
- "@types/react": "~19.2.0",
37
- "@types/react-dom": "~19.2.0",
37
+ "@types/react": "~19.2.2",
38
+ "@types/react-dom": "~19.2.2",
38
39
  "react": "~19.2.0",
39
40
  "react-dom": "~19.2.0"
40
41
  },
package/src/index.ts CHANGED
@@ -16,7 +16,9 @@ export * from './useIsFocused';
16
16
  export * from './useMediaQuery';
17
17
  export * from './useMulticastObservable';
18
18
  export * from './useRefCallback';
19
- export * from './useResize';
19
+ export * from './useViewportResize';
20
20
  export * from './useSignals';
21
21
  export * from './useTimeout';
22
22
  export * from './useTransitions';
23
+
24
+ export { useSize, useScroller } from 'mini-virtual-list';
@@ -7,6 +7,7 @@ import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
7
7
  /**
8
8
  * A stateful hook with a controlled value.
9
9
  * NOTE: Be careful not to provide an inlinde default array.
10
+ * @deprecated Use Radix `useControllableState`.
10
11
  */
11
12
  export const useControlledState = <T>(
12
13
  controlledValue: T,
@@ -3,12 +3,12 @@
3
3
  //
4
4
 
5
5
  import { useCallback } from '@preact-signals/safe-react/react';
6
- import { type Dispatch, type MutableRefObject, type SetStateAction, useEffect, useRef, useState } from 'react';
6
+ import { type Dispatch, type RefObject, type SetStateAction, useEffect, useRef, useState } from 'react';
7
7
 
8
8
  /**
9
9
  * Like `useState` but with an additional dynamic value.
10
10
  */
11
- export const useStateWithRef = <T>(valueParam: T): [T, Dispatch<SetStateAction<T>>, MutableRefObject<T>] => {
11
+ export const useStateWithRef = <T>(valueParam: T): [T, Dispatch<SetStateAction<T>>, RefObject<T>] => {
12
12
  const [value, setValue] = useState<T>(valueParam);
13
13
  const valueRef = useRef<T>(valueParam);
14
14
  const setter = useCallback<Dispatch<SetStateAction<T>>>((value) => {
@@ -29,7 +29,7 @@ export const useStateWithRef = <T>(valueParam: T): [T, Dispatch<SetStateAction<T
29
29
  /**
30
30
  * Ref that is updated by a dependency.
31
31
  */
32
- export const useDynamicRef = <T>(value: T): MutableRefObject<T> => {
32
+ export const useDynamicRef = <T>(value: T): RefObject<T> => {
33
33
  const valueRef = useRef<T>(value);
34
34
  useEffect(() => {
35
35
  valueRef.current = value;
@@ -2,25 +2,28 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { type ForwardedRef, useEffect, useRef } from 'react';
5
+ import { type ForwardedRef, type RefObject, useEffect, useRef } from 'react';
6
6
 
7
7
  /**
8
8
  * Combines a possibly undefined forwarded ref with a locally defined ref.
9
- * @deprecated Use `useComposedRefs` from @radix-ui/react-compose-refs
10
9
  */
11
- export const useForwardedRef = <T>(ref: ForwardedRef<T>) => {
12
- const innerRef = useRef<T>(null);
10
+ export const useForwardedRef = <T>(ref: ForwardedRef<T>): RefObject<T | null> => {
11
+ const innerRef = useRef<T | null>(null);
13
12
  useEffect(() => {
14
- if (!ref) {
15
- return;
16
- }
17
-
18
- if (typeof ref === 'function') {
19
- ref(innerRef.current);
20
- } else {
21
- ref.current = innerRef.current;
22
- }
23
- });
13
+ updateRef(ref, innerRef.current);
14
+ }, [ref]);
24
15
 
25
16
  return innerRef;
26
17
  };
18
+
19
+ export const updateRef = <T>(ref: ForwardedRef<T>, value: T): void => {
20
+ if (!ref) {
21
+ return;
22
+ }
23
+
24
+ if (typeof ref === 'function') {
25
+ ref(value);
26
+ } else {
27
+ ref.current = value;
28
+ }
29
+ };
@@ -29,8 +29,7 @@ const breakpointMediaQueries: Record<string, string> = {
29
29
  * @see Docs https://chakra-ui.com/docs/hooks/use-media-query
30
30
  */
31
31
  export const useMediaQuery = (query: string | string[], options: UseMediaQueryOptions = {}): boolean[] => {
32
- // TODO(wittjosiah): Why is the default here true?
33
- const { ssr = true, fallback } = options;
32
+ const { ssr = false, fallback } = options;
34
33
 
35
34
  const queries = (Array.isArray(query) ? query : [query]).map((query) =>
36
35
  query in breakpointMediaQueries ? breakpointMediaQueries[query] : query,
@@ -48,7 +48,9 @@ export const useDidTransition = <T>(
48
48
  * Executes a callback function when a specified transition occurs in a value.
49
49
  *
50
50
  * This function utilizes the `useDidTransition` hook to monitor changes in `currentValue`.
51
- * When `currentValue` transitions from `fromValue` to `toValue`, the provided `callback` function is executed. */
51
+ * When `currentValue` transitions from `fromValue` to `toValue`, the provided `callback` function is executed.
52
+ */
53
+ // TODO(wittjosiah): Seems overwrought.
52
54
  export const useOnTransition = <T>(
53
55
  currentValue: T,
54
56
  fromValue: T | ((value: T) => boolean),
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { useLayoutEffect, useMemo } from 'react';
6
6
 
7
- export const useResize = (
7
+ export const useViewportResize = (
8
8
  handler: (event?: Event) => void,
9
9
  deps: Parameters<typeof useLayoutEffect>[1] = [],
10
10
  delay: number = 800,
@@ -1,3 +0,0 @@
1
- import { useLayoutEffect } from 'react';
2
- export declare const useResize: (handler: (event?: Event) => void, deps?: Parameters<typeof useLayoutEffect>[1], delay?: number) => void;
3
- //# sourceMappingURL=useResize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useResize.d.ts","sourceRoot":"","sources":["../../../src/useResize.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAW,MAAM,OAAO,CAAC;AAEjD,eAAO,MAAM,SAAS,GACpB,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EAChC,OAAM,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAM,EAChD,QAAO,MAAY,SAiBpB,CAAC"}