useid-polyfill 1.0.3 → 1.0.4

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
@@ -29,10 +29,15 @@ function FormField({ label }: { label: string }) {
29
29
 
30
30
  ## API
31
31
 
32
- ### `useId(): string | undefined`
32
+ ### `useId()`
33
33
 
34
34
  Returns a unique, stable ID string. On React 18+, delegates to the native `React.useId()`.
35
35
 
36
+ TypeScript return type is conditional on your installed React typings:
37
+
38
+ - React 18+ typings: `string`
39
+ - React 16/17 typings: `string | undefined`
40
+
36
41
  On React 16/17 during SSR, returns `undefined` on the initial server render and hydration pass, then resolves to a string ID after a layout effect. This avoids hydration mismatches.
37
42
 
38
43
  ## SSR Caveats
package/dist/index.d.mts CHANGED
@@ -1,3 +1,8 @@
1
- declare const useId: () => string | undefined;
1
+ import * as React from 'react';
2
+
3
+ type UseId = typeof React extends {
4
+ useId: (...args: never[]) => infer R;
5
+ } ? () => R : () => string | undefined;
6
+ declare const useId: UseId;
2
7
 
3
8
  export { useId };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
- declare const useId: () => string | undefined;
1
+ import * as React from 'react';
2
+
3
+ type UseId = typeof React extends {
4
+ useId: (...args: never[]) => infer R;
5
+ } ? () => R : () => string | undefined;
6
+ declare const useId: UseId;
2
7
 
3
8
  export { useId };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var a=Object.create;var d=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var n in t)d(e,n,{get:t[n],enumerable:!0})},r=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!g.call(e,s)&&s!==n&&d(e,s,{get:()=>t[s],enumerable:!(i=p(t,s))||i.enumerable});return e};var x=(e,t,n)=>(n=e!=null?a(I(e)):{},r(t||!e||!e.__esModule?d(n,"default",{value:e,enumerable:!0}):n,e)),y=e=>r(d({},"__esModule",{value:!0}),e);var $={};l($,{useId:()=>c});module.exports=y($);var E=x(require("react")),o=require("react"),R={...E},h=0,w=Math.random().toString(36).slice(2,6),u=()=>`uid-${w}${h++}`,L=typeof window!="undefined"?o.useLayoutEffect:o.useEffect,f=!1;function S(){let[e,t]=(0,o.useState)(()=>f?u():void 0);return L(()=>{e===void 0&&t(u())},[]),(0,o.useEffect)(()=>{f||(f=!0)},[]),e}var c=R.useId||S;0&&(module.exports={useId});
1
+ "use strict";var a=Object.create;var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var n in t)o(e,n,{get:t[n],enumerable:!0})},i=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of I(t))!m.call(e,d)&&d!==n&&o(e,d,{get:()=>t[d],enumerable:!(r=p(t,d))||r.enumerable});return e};var y=(e,t,n)=>(n=e!=null?a(g(e)):{},i(t||!e||!e.__esModule?o(n,"default",{value:e,enumerable:!0}):n,e)),R=e=>i(o({},"__esModule",{value:!0}),e);var L={};l(L,{useId:()=>c});module.exports=R(L);var x=y(require("react")),s=require("react"),E={...x},U=0,h=Math.random().toString(36).slice(2,6),u=()=>`uid-${h}${U++}`,v=typeof window!="undefined"?s.useLayoutEffect:s.useEffect,f=!1;function w(){let[e,t]=(0,s.useState)(()=>f?u():void 0);return v(()=>{e===void 0&&t(u())},[]),(0,s.useEffect)(()=>{f||(f=!0)},[]),e}var c=E.useId||w;0&&(module.exports={useId});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import*as d from"react";import{useState as f,useEffect as o,useLayoutEffect as i}from"react";var r={...d},u=0,c=Math.random().toString(36).slice(2,6),n=()=>`uid-${c}${u++}`,a=typeof window!="undefined"?i:o,e=!1;function p(){let[t,s]=f(()=>e?n():void 0);return a(()=>{t===void 0&&s(n())},[]),o(()=>{e||(e=!0)},[]),t}var m=r.useId||p;export{m as useId};
1
+ import*as o from"react";import{useState as f,useEffect as s,useLayoutEffect as r}from"react";var i={...o},u=0,c=Math.random().toString(36).slice(2,6),n=()=>`uid-${c}${u++}`,a=typeof window!="undefined"?r:s,e=!1;function p(){let[t,d]=f(()=>e?n():void 0);return a(()=>{t===void 0&&d(n())},[]),s(()=>{e||(e=!0)},[]),t}var I=i.useId||p;export{I as useId};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "useid-polyfill",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "React useId polyfill for React 16/17 with SSR support",
5
5
  "author": {
6
6
  "name": "Dermot Hughes",