@koobiq/react-core 0.0.1-beta.1 → 0.0.1-beta.10

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/README.md CHANGED
@@ -1 +1,3 @@
1
1
  # @koobiq/react-core
2
+
3
+ Common utilities and hooks used by Koobiq React packages.
@@ -11,3 +11,4 @@ export * from './useIsFirstRender/index.js';
11
11
  export * from './useEventListener/index.js';
12
12
  export * from './useResizeObserver/index.js';
13
13
  export * from './useElementSize/index.js';
14
+ export * from './useRefs/index.js';
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useState, useCallback } from "react";
2
3
  function useBoolean(defaultValue = false) {
3
4
  const [value, setValue] = useState(defaultValue);
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useRef, useImperativeHandle } from "react";
2
3
  function useDOMRef(ref) {
3
4
  const domRef = useRef(null);
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useLayoutEffect, useEffect } from "react";
2
3
  import { isBrowser } from "../../utils/isBrowser.js";
3
4
  const useIsomorphicEffect = isBrowser() ? useLayoutEffect : useEffect;
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useRef, useEffect } from "react";
2
3
  function usePrevious(value) {
3
4
  const ref = useRef(null);
@@ -0,0 +1 @@
1
+ export * from './useRefs';
@@ -0,0 +1,3 @@
1
+ import { type RefObject } from 'react';
2
+ export type UseRefsReturn<T, Keys extends number | readonly string[]> = Keys extends readonly string[] ? Record<Keys[number], RefObject<T>> : Array<RefObject<T>>;
3
+ export declare const useRefs: <T, Keys extends number | readonly string[] = number>(keys: Keys, deps?: unknown[]) => UseRefsReturn<T, Keys>;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { useMemo, createRef } from "react";
3
+ import { isNumber } from "../../utils/typeGuards/isNumber.js";
4
+ const useRefs = (keys, deps = []) => useMemo(() => {
5
+ if (!isNumber(keys)) {
6
+ return Object.fromEntries(
7
+ keys.map((key) => [key, createRef()])
8
+ );
9
+ }
10
+ return new Array(keys).fill(0).map(() => createRef());
11
+ }, [isNumber(keys) ? keys : keys.join("-"), ...deps]);
12
+ export {
13
+ useRefs
14
+ };
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useState, useEffect } from "react";
2
3
  import { isBrowser } from "../../utils/isBrowser.js";
3
4
  const useSsr = () => {
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ import { useIsFirstRender } from "./hooks/useIsFirstRender/useIsFirstRender.js";
16
16
  import { useEventListener } from "./hooks/useEventListener/useEventListener.js";
17
17
  import { useResizeObserver } from "./hooks/useResizeObserver/useResizeObserver.js";
18
18
  import { useElementSize } from "./hooks/useElementSize/useElementSize.js";
19
+ import { useRefs } from "./hooks/useRefs/useRefs.js";
19
20
  import { polymorphicForwardRef } from "./utils/polymorphicForwardRef.js";
20
21
  import { isNotNil } from "./utils/typeGuards/isNotNil.js";
21
22
  import { isString } from "./utils/typeGuards/isString.js";
@@ -49,6 +50,7 @@ export {
49
50
  useMutableRef,
50
51
  usePress,
51
52
  usePrevious,
53
+ useRefs,
52
54
  useResizeObserver,
53
55
  useSsr,
54
56
  useToggleState
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koobiq/react-core",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.10",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {