From 7a10418ab4d6c3f4125bc3fd1731cc0fdc2214db Mon Sep 17 00:00:00 2001 From: Ken Snyder Date: Fri, 7 Jun 2024 09:46:00 -0600 Subject: [PATCH] Use React.useId() instead of lodash.uniqueid (#53) * use React.useId() instead of lodash.uniqueid * Fallback useId for React < 18 --- package.json | 1 - src/FileIcon.js | 9 +- .../__snapshots__/FileIcon.test.js.snap | 426 +++++++++--------- yarn.lock | 5 - 4 files changed, 220 insertions(+), 221 deletions(-) diff --git a/package.json b/package.json index f1f8a40..65710af 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "license": "MIT", "dependencies": { "colord": "^2.9.3", - "lodash.uniqueid": "^4.0.1", "prop-types": "^15.7.2" }, "devDependencies": { diff --git a/src/FileIcon.js b/src/FileIcon.js index 9fc11f8..858d98b 100644 --- a/src/FileIcon.js +++ b/src/FileIcon.js @@ -2,7 +2,6 @@ import React from 'react'; import PropTypes from 'prop-types'; import { colord, extend as extendColord } from 'colord'; import namesPlugin from 'colord/plugins/names'; -import uniqueId from 'lodash.uniqueid'; import glyphs from './glyphs'; @@ -70,6 +69,11 @@ const FOLD = { const LABEL_HEIGHT = 14; +const useId = React.useId || (() => { + let i = 0; + return () => i++; +})(); + export const FileIcon = ({ color = 'whitesmoke', extension, @@ -84,7 +88,8 @@ export const FileIcon = ({ radius = 4, type, }) => { - const UNIQUE_ID = uniqueId(); + const id = useId(); + const UNIQUE_ID = typeof jest === 'undefined' ? id : ''; return ( border radius variations render correctly 1`] = ` > border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` > border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` > border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` > border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` > border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` > border radius variations render correctly 1`] = ` /> border radius variations render correctly 1`] = ` border radius variations render correctly 1`] = ` /> color variations render correctly 1`] = ` > color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` id="label" > color variations render correctly 1`] = ` > color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` id="label" > color variations render correctly 1`] = ` > color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` id="label" > color variations render correctly 1`] = ` > color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` id="label" > color variations render correctly 1`] = ` > color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` id="label" > color variations render correctly 1`] = ` > color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` color variations render correctly 1`] = ` /> color variations render correctly 1`] = ` id="label" > file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` > file type glyphs render correctly 1`] = ` /> file type glyphs render correctly 1`] = ` file type glyphs render correctly 1`] = ` /> label colors render correctly 1`] = ` > label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` id="label" > label colors render correctly 1`] = ` > label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` id="label" > label colors render correctly 1`] = ` > label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` id="label" > label colors render correctly 1`] = ` > label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` id="label" > label colors render correctly 1`] = ` > label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` id="label" > label colors render correctly 1`] = ` > label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` label colors render correctly 1`] = ` /> label colors render correctly 1`] = ` id="label" > renders uppercase label when labelUppercase is true 1`] = > renders uppercase label when labelUppercase is true 1`] = /> renders uppercase label when labelUppercase is true 1`] = renders uppercase label when labelUppercase is true 1`] = /> renders uppercase label when labelUppercase is true 1`] = id="label" > standard arrangements render correctly 1`] = ` > standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` standard arrangements render correctly 1`] = ` y="0" /> standard arrangements render correctly 1`] = ` > standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` > standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` > standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` id="label" > standard arrangements render correctly 1`] = ` > standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` standard arrangements render correctly 1`] = ` /> standard arrangements render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` id="label" > unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` y="0" /> unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` y="0" /> unique file icons render correctly 1`] = ` > unique file icons render correctly 1`] = ` /> unique file icons render correctly 1`] = ` unique file icons render correctly 1`] = ` y="0" />