From ebd638865195ce8a599f7d5f253ec669f7af1db8 Mon Sep 17 00:00:00 2001 From: Andrew Musgrave Date: Mon, 9 Dec 2019 17:07:52 -0500 Subject: [PATCH 1/2] Converted FormLayout to a functional component --- src/components/FormLayout/FormLayout.tsx | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) 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)) { From 01d60c50f61d647a0f88bde1072fb8c613eaee9d Mon Sep 17 00:00:00 2001 From: Andrew Musgrave Date: Mon, 16 Dec 2019 12:53:41 -0500 Subject: [PATCH 2/2] changelog --- UNRELEASED.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UNRELEASED.md b/UNRELEASED.md index f50d13b618d..965e8712b9a 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -14,4 +14,6 @@ ### Code quality +- Converted `FormLayout` into a functional component ([#2539](https://github.com/Shopify/polaris-react/pull/2539)) + ### Deprecations