@react-aria/utils
Advanced tools
Comparing version 3.0.0-nightly.710 to 3.0.0-nightly.715
@@ -12,5 +12,5 @@ var _clsx = $parcel$interopDefault(require("clsx")); | ||
var { | ||
useState, | ||
useEffect, | ||
useRef, | ||
useEffect | ||
useState | ||
} = _react2; | ||
@@ -34,5 +34,28 @@ | ||
function useId(defaultId) { | ||
let isRendering = useRef(true); | ||
isRendering.current = true; | ||
let [value, setValue] = useState(defaultId); | ||
let nextId = useRef(null); // don't memo this, we want it new each render so that the Effects always run | ||
let updateValue = val => { | ||
if (!isRendering.current) { | ||
setValue(val); | ||
} else { | ||
nextId.current = val; | ||
} | ||
}; | ||
useLayoutEffect(() => { | ||
isRendering.current = false; | ||
}, [updateValue]); | ||
useEffect(() => { | ||
let newId = nextId.current; | ||
if (newId) { | ||
setValue(newId); | ||
nextId.current = null; | ||
} | ||
}, [setValue, updateValue]); | ||
let res = useSSRSafeId(value); | ||
$f09fcd7f5f367fc80aacfeac62ed2$var$map.set(res, setValue); | ||
$f09fcd7f5f367fc80aacfeac62ed2$var$map.set(res, updateValue); | ||
return res; | ||
@@ -39,0 +62,0 @@ } |
import _clsx from "clsx"; | ||
import { useSSRSafeId } from "@react-aria/ssr"; | ||
import _react, { useState, useRef, useEffect } from "react"; | ||
import _react, { useEffect, useRef, useState } from "react"; | ||
// During SSR, React emits a warning when calling useLayoutEffect. | ||
@@ -15,5 +15,28 @@ // Since neither useLayoutEffect nor useEffect run on the server, | ||
export function useId(defaultId) { | ||
let isRendering = useRef(true); | ||
isRendering.current = true; | ||
let [value, setValue] = useState(defaultId); | ||
let nextId = useRef(null); // don't memo this, we want it new each render so that the Effects always run | ||
let updateValue = val => { | ||
if (!isRendering.current) { | ||
setValue(val); | ||
} else { | ||
nextId.current = val; | ||
} | ||
}; | ||
useLayoutEffect(() => { | ||
isRendering.current = false; | ||
}, [updateValue]); | ||
useEffect(() => { | ||
let newId = nextId.current; | ||
if (newId) { | ||
setValue(newId); | ||
nextId.current = null; | ||
} | ||
}, [setValue, updateValue]); | ||
let res = useSSRSafeId(value); | ||
$f8b5fdd96fb429d7102983f777c41307$var$map.set(res, setValue); | ||
$f8b5fdd96fb429d7102983f777c41307$var$map.set(res, updateValue); | ||
return res; | ||
@@ -20,0 +43,0 @@ } |
{ | ||
"name": "@react-aria/utils", | ||
"version": "3.0.0-nightly.710+da1f0a8a", | ||
"version": "3.0.0-nightly.715+bd9852ce", | ||
"description": "Spectrum UI components in React", | ||
@@ -21,8 +21,8 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/ssr": "3.0.1-nightly.2388+da1f0a8a", | ||
"@react-types/shared": "3.0.0-nightly.710+da1f0a8a", | ||
"@react-aria/ssr": "3.0.1-nightly.2393+bd9852ce", | ||
"@react-types/shared": "3.0.0-nightly.715+bd9852ce", | ||
"clsx": "^1.1.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
"react": "^16.8.0 || ^17.0.0-rc.1" | ||
}, | ||
@@ -32,3 +32,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "da1f0a8a149db773b61c8ae61a99ec0139db7b29" | ||
"gitHead": "bd9852ce71c11a970a135668373e16cf8962dc3c" | ||
} |
@@ -13,5 +13,5 @@ /* | ||
import {useEffect, useRef, useState} from 'react'; | ||
import {useLayoutEffect} from './useLayoutEffect'; | ||
import {useSSRSafeId} from '@react-aria/ssr'; | ||
import {useState} from 'react'; | ||
@@ -25,5 +25,29 @@ let map: Map<string, (v: string) => void> = new Map(); | ||
export function useId(defaultId?: string): string { | ||
let isRendering = useRef(true); | ||
isRendering.current = true; | ||
let [value, setValue] = useState(defaultId); | ||
let nextId = useRef(null); | ||
// don't memo this, we want it new each render so that the Effects always run | ||
let updateValue = (val) => { | ||
if (!isRendering.current) { | ||
setValue(val); | ||
} else { | ||
nextId.current = val; | ||
} | ||
}; | ||
useLayoutEffect(() => { | ||
isRendering.current = false; | ||
}, [updateValue]); | ||
useEffect(() => { | ||
let newId = nextId.current; | ||
if (newId) { | ||
setValue(newId); | ||
nextId.current = null; | ||
} | ||
}, [setValue, updateValue]); | ||
let res = useSSRSafeId(value); | ||
map.set(res, setValue); | ||
map.set(res, updateValue); | ||
return res; | ||
@@ -30,0 +54,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
179222
1929
+ Addedreact@17.0.2(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact@16.14.0(transitive)
- Removedreact-is@16.13.1(transitive)