Skip to content

Commit

Permalink
fix(EmptyState): added useId handling for older react version (#6620)
Browse files Browse the repository at this point in the history
* fix(EmptyState): added useId handling for older react version

* fix(EmptyState): fixed imports for useId

---------

Co-authored-by: Sean Anderson <[email protected]>
  • Loading branch information
elycheea and sean-anderson-ibm authored Dec 18, 2024
1 parent a8985c2 commit 45af420
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

// Import portions of React that are needed.
import React, { useId } from 'react';
import React from 'react';

// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { useId } from '../../../global/js/utils/useId';

// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

// Import portions of React that are needed.
import React, { useId } from 'react';
import React from 'react';

// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { useId } from '../../../global/js/utils/useId';

// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

// Import portions of React that are needed.
import React, { useId } from 'react';
import React from 'react';

// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { useId } from '../../../global/js/utils/useId';

// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

// Import portions of React that are needed.
import React, { useId } from 'react';
import React from 'react';

// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { useId } from '../../../global/js/utils/useId';

// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

// Import portions of React that are needed.
import React, { useId } from 'react';
import React from 'react';

// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { useId } from '../../../global/js/utils/useId';

// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

// Import portions of React that are needed.
import React, { useId } from 'react';
import React from 'react';

// Other standard imports.
import PropTypes from 'prop-types';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { useId } from '../../../global/js/utils/useId';

// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
Expand Down
21 changes: 21 additions & 0 deletions packages/ibm-products/src/global/js/utils/useId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright IBM Corp. 2021, 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';
import uuidv4 from './uuidv4';

// This tricks bundlers so they can't statically analyze this and produce
// compilation warnings/errors.
// https://github.com/webpack/webpack/issues/14814
// https://github.com/mui/material-ui/issues/41190
const _React = { ...React };

/**
* Uses React 18's built-in `useId()` when available, or falls back to
* using uuidv4 otherwise
*/
export const useId = _React.useId ? _React.useId : uuidv4;

0 comments on commit 45af420

Please sign in to comment.