From b830556de552145512d1297b5066bd3a1b29cdb9 Mon Sep 17 00:00:00 2001 From: jacobo-dominguez-wgu Date: Tue, 23 Sep 2025 12:05:49 -0600 Subject: [PATCH 1/2] chore: removing unnecessary react imports part 11 --- babel.config.json | 4 +-- component-generator/templates/index.jsx | 4 +-- component-generator/templates/test.jsx | 1 - src/Tooltip/Tooltip.test.tsx | 1 - src/Tooltip/index.tsx | 4 +-- .../TransitionReplace.test.jsx | 1 - src/TransitionReplace/index.jsx | 28 +++++++++-------- src/Truncate/Truncate.test.jsx | 1 - src/Truncate/index.jsx | 6 ++-- .../ValidationMessage.test.jsx | 1 - src/ValidationMessage/index.jsx | 4 +-- src/utils/types/bootstrap.test.tsx | 30 +++++++++++-------- src/utils/types/bootstrap.ts | 6 ++-- 13 files changed, 46 insertions(+), 45 deletions(-) diff --git a/babel.config.json b/babel.config.json index 6815ebd872..f2421ecf77 100644 --- a/babel.config.json +++ b/babel.config.json @@ -1,14 +1,14 @@ { "presets": [ ["@babel/preset-env", { "modules": false } ], - ["@babel/preset-react", { "useSpread": true } ], + ["@babel/preset-react", { "useSpread": true, "runtime": "automatic" } ], "@babel/preset-typescript" ], "env": { "test": { "presets": [ ["@babel/preset-env", {}], - ["@babel/preset-react", { "useSpread": true } ], + ["@babel/preset-react", { "useSpread": true, "runtime": "automatic" } ], "@babel/preset-typescript" ] } diff --git a/component-generator/templates/index.jsx b/component-generator/templates/index.jsx index 86866e97cd..94db0ab59c 100644 --- a/component-generator/templates/index.jsx +++ b/component-generator/templates/index.jsx @@ -1,8 +1,8 @@ -import React from 'react'; +import { forwardRef } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -const componentName = React.forwardRef(({ className, children }, ref) => ( +const componentName = forwardRef(({ className, children }, ref) => (
{children}
diff --git a/component-generator/templates/test.jsx b/component-generator/templates/test.jsx index 1785cc404c..aedd6ee98d 100644 --- a/component-generator/templates/test.jsx +++ b/component-generator/templates/test.jsx @@ -1,4 +1,3 @@ -import React from 'react'; import renderer from 'react-test-renderer'; import componentName from './index'; diff --git a/src/Tooltip/Tooltip.test.tsx b/src/Tooltip/Tooltip.test.tsx index f67718340d..a3ff25fbee 100644 --- a/src/Tooltip/Tooltip.test.tsx +++ b/src/Tooltip/Tooltip.test.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import { render, screen } from '@testing-library/react'; import Tooltip from '.'; diff --git a/src/Tooltip/index.tsx b/src/Tooltip/index.tsx index 9d9131b459..0f1bee639f 100644 --- a/src/Tooltip/index.tsx +++ b/src/Tooltip/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import { forwardRef } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import BaseTooltip, { type TooltipProps as BaseTooltipProps } from 'react-bootstrap/Tooltip'; @@ -27,7 +27,7 @@ const PLACEMENT_VARIANTS: Placement[] = [ 'left-start', ]; -const Tooltip: ComponentWithAsProp<'div', TooltipProps> = React.forwardRef(({ +const Tooltip: ComponentWithAsProp<'div', TooltipProps> = forwardRef(({ children, variant, ...props diff --git a/src/TransitionReplace/TransitionReplace.test.jsx b/src/TransitionReplace/TransitionReplace.test.jsx index b7531c1f38..d8d8e59b22 100644 --- a/src/TransitionReplace/TransitionReplace.test.jsx +++ b/src/TransitionReplace/TransitionReplace.test.jsx @@ -1,5 +1,4 @@ /* eslint-disable no-plusplus, react/prop-types */ -import React from 'react'; import { render } from '@testing-library/react'; import TransitionReplace from '.'; diff --git a/src/TransitionReplace/index.jsx b/src/TransitionReplace/index.jsx index f39bcd48e0..2bd2d1f4a5 100644 --- a/src/TransitionReplace/index.jsx +++ b/src/TransitionReplace/index.jsx @@ -1,9 +1,9 @@ -import React from 'react'; +import { Children, Component } from 'react'; import PropTypes from 'prop-types'; import { CSSTransition, TransitionGroup } from 'react-transition-group'; import classNames from 'classnames'; -class TransitionReplace extends React.Component { +class TransitionReplace extends Component { constructor(props) { super(props); @@ -117,17 +117,19 @@ class TransitionReplace extends React.Component { render() { return ( - - {React.Children.map(this.props.children, this.renderChildTransition, this)} - + ( + + {Children.map(this.props.children, this.renderChildTransition, this)} + + ) ); } } diff --git a/src/Truncate/Truncate.test.jsx b/src/Truncate/Truncate.test.jsx index d1cc120c85..f601daca95 100644 --- a/src/Truncate/Truncate.test.jsx +++ b/src/Truncate/Truncate.test.jsx @@ -1,4 +1,3 @@ -import React from 'react'; import { render, screen } from '@testing-library/react'; import Truncate from '.'; diff --git a/src/Truncate/index.jsx b/src/Truncate/index.jsx index 292b7e2b7f..ee295b8fa7 100644 --- a/src/Truncate/index.jsx +++ b/src/Truncate/index.jsx @@ -1,5 +1,5 @@ -import React, { - useLayoutEffect, useRef, useEffect, +import { + createElement, useLayoutEffect, useRef, useEffect, } from 'react'; import PropTypes from 'prop-types'; import { truncateLines } from './utils'; @@ -34,7 +34,7 @@ function TruncateDeprecated({ } }, [children, ellipsis, lines, onTruncate, whiteSpace, width]); - return React.createElement(elementType, { + return createElement(elementType, { ref: textContainer, className, }); diff --git a/src/ValidationMessage/ValidationMessage.test.jsx b/src/ValidationMessage/ValidationMessage.test.jsx index 785c4f24c2..d11ab1ba8c 100644 --- a/src/ValidationMessage/ValidationMessage.test.jsx +++ b/src/ValidationMessage/ValidationMessage.test.jsx @@ -1,4 +1,3 @@ -import React from 'react'; import { render, screen } from '@testing-library/react'; import ValidationMessage from '.'; diff --git a/src/ValidationMessage/index.jsx b/src/ValidationMessage/index.jsx index e944a0eb2c..644c92dc55 100644 --- a/src/ValidationMessage/index.jsx +++ b/src/ValidationMessage/index.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import { Component } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; @@ -26,7 +26,7 @@ const defaultProps = { variantIconDescription: '', }; -class ValidationMessage extends React.Component { +class ValidationMessage extends Component { getVariantFeedbackClassName() { const { variant } = this.props; let className; diff --git a/src/utils/types/bootstrap.test.tsx b/src/utils/types/bootstrap.test.tsx index 0346c5d2b4..f28471747c 100644 --- a/src/utils/types/bootstrap.test.tsx +++ b/src/utils/types/bootstrap.test.tsx @@ -1,16 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import React from 'react'; +import type { + ElementType, FC, MouseEventHandler, RefObject, +} from 'react'; + +import { forwardRef } from 'react'; import type { BsPropsWithAs, ComponentWithAsProp } from './bootstrap'; // Note: these are type-only tests. They don't actually do much at runtime; the important checks are at transpile time. describe('BsPropsWithAs', () => { - interface Props extends BsPropsWithAs { + interface Props extends BsPropsWithAs { otherProp?: number; } it('defines optional bsPrefix, className, and as but no other props', () => { - const checkProps = (_props: Props) => {}; + const checkProps = (_props: Props) => {}; // These are all valid props per the prop definition: checkProps({ }); checkProps({ bsPrefix: 'bs' }); @@ -34,43 +38,43 @@ describe('ComponentWithAsProp', () => { customProp?: string; } const MyComponent: ComponentWithAsProp<'div', MyProps> = ( - React.forwardRef( + forwardRef( ({ as: Inner = 'div', ...props }, ref) => , ) ); // eslint-disable-next-line react/function-component-definition - const CustomComponent: React.FC<{ requiredProp: string }> = () => ; + const CustomComponent: FC<{ requiredProp: string }> = () => ; it('is defined to wrap a
by default, and accepts related props', () => { // This is valid - by default it is a DIV so accepts props and ref related to DIV: - const divClick: React.MouseEventHandler = () => {}; - const divRef: React.RefObject = { current: null }; + const divClick: MouseEventHandler = () => {}; + const divRef: RefObject = { current: null }; const valid = ; }); it('is defined to wrap a
by default, and rejects unrelated props', () => { - const btnRef: React.RefObject = { current: null }; + const btnRef: RefObject = { current: null }; // @ts-expect-error because the ref is to a