Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/hooks/useId.ts
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useState } from "react";
8
9
let currentId = 0;
10
const getId = () => currentId++;
11
12
//TODO: Replace this with React.useId once we upgrade to v18
13
export function useId({ prefix = "el" } = {}) {
14
const [id] = useState(getId);
15
16
return `${prefix}_${id}`;
17
}
18
19