@react-aria/utils 3.12.0 → 3.13.2

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/src/useId.ts CHANGED
@@ -22,28 +22,17 @@ let idsUpdaterMap: Map<string, (v: string) => void> = new Map();
22
22
  * @param defaultId - Default component id.
23
23
  */
24
24
  export function useId(defaultId?: string): string {
25
- let isRendering = useRef(true);
26
- isRendering.current = true;
27
25
  let [value, setValue] = useState(defaultId);
28
26
  let nextId = useRef(null);
29
27
 
30
28
  let res = useSSRSafeId(value);
31
29
 
32
- // don't memo this, we want it new each render so that the Effects always run
33
- let updateValue = (val) => {
34
- if (!isRendering.current) {
35
- setValue(val);
36
- } else {
37
- nextId.current = val;
38
- }
39
- };
30
+ let updateValue = useCallback((val) => {
31
+ nextId.current = val;
32
+ }, []);
40
33
 
41
34
  idsUpdaterMap.set(res, updateValue);
42
35
 
43
- useLayoutEffect(() => {
44
- isRendering.current = false;
45
- }, [updateValue]);
46
-
47
36
  useLayoutEffect(() => {
48
37
  let r = res;
49
38
  return () => {
@@ -51,13 +40,16 @@ export function useId(defaultId?: string): string {
51
40
  };
52
41
  }, [res]);
53
42
 
43
+ // This cannot cause an infinite loop because the ref is updated first.
44
+ // eslint-disable-next-line
54
45
  useEffect(() => {
55
46
  let newId = nextId.current;
56
47
  if (newId) {
57
- setValue(newId);
58
48
  nextId.current = null;
49
+ setValue(newId);
59
50
  }
60
- }, [setValue, updateValue]);
51
+ });
52
+
61
53
  return res;
62
54
  }
63
55
 
@@ -5,11 +5,11 @@ function hasResizeObserver() {
5
5
  }
6
6
 
7
7
  type useResizeObserverOptionsType<T> = {
8
- ref: RefObject<T>,
8
+ ref: RefObject<T | undefined>,
9
9
  onResize: () => void
10
10
  }
11
11
 
12
- export function useResizeObserver<T extends HTMLElement>(options: useResizeObserverOptionsType<T>) {
12
+ export function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>) {
13
13
  const {ref, onResize} = options;
14
14
 
15
15
  useEffect(() => {
package/src/number.ts DELETED
@@ -1,13 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- export {clamp, snapValueToStep} from '@react-stately/utils';