From 1225d2596923bc5ca816e110ee5d1416283b8fc9 Mon Sep 17 00:00:00 2001 From: Anna Wen <54281166+annawen1@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:40:19 -0500 Subject: [PATCH] chore: add react prefix hook for react package (#345) --- packages/utilities/package.json | 4 ++++ packages/utilities/src/index.js | 1 + packages/utilities/src/usePrefix.js | 18 ++++++++++++++++++ yarn.lock | 2 ++ 4 files changed, 25 insertions(+) create mode 100644 packages/utilities/src/usePrefix.js diff --git a/packages/utilities/package.json b/packages/utilities/package.json index 3e944808..dd7a541f 100644 --- a/packages/utilities/package.json +++ b/packages/utilities/package.json @@ -29,6 +29,10 @@ "es/**/*.js", "es/index.js" ], + "dependencies": { + "react": "^18.3.1", + "react-dom": "^18.3.1" + }, "devDependencies": { "@rollup/plugin-babel": "^6.0.4", "babel-cli": "^6.26.0" diff --git a/packages/utilities/src/index.js b/packages/utilities/src/index.js index f1146913..8e0a8d3a 100644 --- a/packages/utilities/src/index.js +++ b/packages/utilities/src/index.js @@ -8,3 +8,4 @@ */ export * from './settings/index.js'; +export * from './usePrefix.js'; diff --git a/packages/utilities/src/usePrefix.js b/packages/utilities/src/usePrefix.js new file mode 100644 index 00000000..703713d0 --- /dev/null +++ b/packages/utilities/src/usePrefix.js @@ -0,0 +1,18 @@ +/** + * Copyright IBM Corp. 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; + +export const PrefixContext = React.createContext('clabs'); + +/** + * Sets the prefix context + * @returns context value + */ +export function usePrefix() { + return React.useContext(PrefixContext); +} diff --git a/yarn.lock b/yarn.lock index b00a5646..83f1fdfc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2594,6 +2594,8 @@ __metadata: dependencies: "@rollup/plugin-babel": "npm:^6.0.4" babel-cli: "npm:^6.26.0" + react: "npm:^18.3.1" + react-dom: "npm:^18.3.1" languageName: unknown linkType: soft