diff --git a/UNRELEASED.md b/UNRELEASED.md index f1fab545779..f06d139c69e 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -24,6 +24,7 @@ ### Code quality +- Converted `BulkActionButton` into a functional component ([#2542](https://github.com/Shopify/polaris-react/pull/2542)) - Converted `Focus` into a functional component ([#2540](https://github.com/Shopify/polaris-react/pull/2540)) ### Deprecations diff --git a/src/components/ResourceList/components/BulkActions/components/BulkActionButton/BulkActionButton.tsx b/src/components/ResourceList/components/BulkActions/components/BulkActionButton/BulkActionButton.tsx index 2e766bfb20f..4dff2328267 100644 --- a/src/components/ResourceList/components/BulkActions/components/BulkActionButton/BulkActionButton.tsx +++ b/src/components/ResourceList/components/BulkActions/components/BulkActionButton/BulkActionButton.tsx @@ -1,6 +1,8 @@ -import React, {createRef} from 'react'; +import React, {useRef} from 'react'; import {DisableableAction} from '../../../../../../types'; import {Button} from '../../../../../Button'; +import {useComponentDidMount} from '../../../../../../utilities/use-component-did-mount'; + import styles from '../../BulkActions.scss'; export type BulkActionButtonProps = { @@ -8,44 +10,37 @@ export type BulkActionButtonProps = { handleMeasurement?(width: number): void; } & DisableableAction; -export class BulkActionButton extends React.PureComponent< - BulkActionButtonProps, - never -> { - private bulkActionButton = createRef(); +export function BulkActionButton({ + handleMeasurement, + url, + external, + onAction, + content, + disclosure, + accessibilityLabel, + disabled, +}: BulkActionButtonProps) { + const bulkActionButton = useRef(null); - componentDidMount() { - const {handleMeasurement} = this.props; - if (handleMeasurement && this.bulkActionButton.current) { - const width = this.bulkActionButton.current.getBoundingClientRect().width; + useComponentDidMount(() => { + if (handleMeasurement && bulkActionButton.current) { + const width = bulkActionButton.current.getBoundingClientRect().width; handleMeasurement(width); } - } - - render() { - const { - url, - external, - onAction, - content, - disclosure, - accessibilityLabel, - disabled, - } = this.props; + }); - return ( -
- -
- ); - } + return ( +
+ +
+ ); }