diff --git a/UNRELEASED.md b/UNRELEASED.md index e17bbb33143..a1655c0c08b 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -24,6 +24,7 @@ ### Code quality +- Converted `FormLayout` into a functional component ([#2539](https://github.com/Shopify/polaris-react/pull/2539)) - 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)) - Converted `Tooltip` into a functional component ([#2543](https://github.com/Shopify/polaris-react/pull/2543)) diff --git a/src/components/FormLayout/FormLayout.tsx b/src/components/FormLayout/FormLayout.tsx index c2055764d82..645b55f23c1 100644 --- a/src/components/FormLayout/FormLayout.tsx +++ b/src/components/FormLayout/FormLayout.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {memo, NamedExoticComponent} from 'react'; import {wrapWithComponent, isElementOfType} from '../../utilities/components'; import {Group, Item} from './components'; @@ -9,19 +9,19 @@ export interface FormLayoutProps { children?: React.ReactNode; } -export class FormLayout extends React.PureComponent { - static Group = Group; +export const FormLayout = memo(function FormLayout({ + children, +}: FormLayoutProps) { + return ( +
+ {React.Children.map(children, wrapChildren)} +
+ ); +}) as NamedExoticComponent & { + Group: typeof Group; +}; - render() { - const {children} = this.props; - - return ( -
- {React.Children.map(children, wrapChildren)} -
- ); - } -} +FormLayout.Group = Group; function wrapChildren(child: React.ReactElement<{}>, index: number) { if (isElementOfType(child, Group)) {