Skip to content

Commit cee78a5

Browse files
authored
chore(docs): replace HOCs with React.memo (#3550)
1 parent 12e4d78 commit cee78a5

File tree

15 files changed

+35
-85
lines changed

15 files changed

+35
-85
lines changed

docs/src/components/ComponentDoc/ComponentControls/ComponentControls.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React from 'react'
33
import universal from 'react-universal-component'
44
import { Menu } from 'semantic-ui-react'
55

6-
import { updateForKeys } from 'docs/src/hoc'
76
import { isBrowser } from 'src/lib'
87
import ComponentControlsCopyLink from './ComponentControlsCopyLink'
98
import ComponentControlsEditCode from './ComponentControlsEditCode'
@@ -12,10 +11,10 @@ import ComponentControlsShowHtml from './ComponentControlsShowHtml'
1211

1312
const ComponentControlsCodeSandbox = isBrowser()
1413
? universal(import('./ComponentControlsCodeSandbox'), {
15-
loading: () => (
16-
<Menu.Item disabled icon={{ loading: true, name: 'spinner', title: 'Loading...' }} />
17-
),
18-
})
14+
loading: () => (
15+
<Menu.Item disabled icon={{ loading: true, name: 'spinner', title: 'Loading...' }} />
16+
),
17+
})
1918
: () => null
2019

2120
const ComponentControls = (props) => {
@@ -54,4 +53,4 @@ ComponentControls.propTypes = {
5453
showHTML: PropTypes.bool,
5554
}
5655

57-
export default updateForKeys(['exampleCode', 'showCode', 'showHTML'])(ComponentControls)
56+
export default React.memo(ComponentControls)

docs/src/components/ComponentDoc/ComponentControls/ComponentControlsCodeSandbox.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import CodeSandboxer from 'react-codesandboxer'
55
import { Menu } from 'semantic-ui-react'
66

77
import { externals } from 'docs/src/components/ComponentDoc/ComponentExample/renderConfig'
8-
import { updateForKeys } from 'docs/src/hoc'
98

109
const appTemplate = `import React from "react";
1110
import ReactDOM from "react-dom";
@@ -50,7 +49,7 @@ ReactDOM.render(
5049
`
5150
const dependencies = _.mapValues(externals, () => 'latest')
5251

53-
class ComponentControlsShowCode extends React.Component {
52+
class ComponentControlsCodeSandbox extends React.Component {
5453
static propTypes = {
5554
exampleCode: PropTypes.string.isRequired,
5655
}
@@ -123,4 +122,4 @@ class ComponentControlsShowCode extends React.Component {
123122
}
124123
}
125124

126-
export default updateForKeys(['exampleCode'])(ComponentControlsShowCode)
125+
export default React.memo(ComponentControlsCodeSandbox)

docs/src/components/ComponentDoc/ComponentExample/ComponentExampleRenderEditor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import React, { PureComponent } from 'react'
44
import { Button, Popup, Segment, Menu } from 'semantic-ui-react'
55

66
import Editor, { EDITOR_BACKGROUND_COLOR } from 'docs/src/components/CodeEditor'
7-
import { updateForKeys } from 'docs/src/hoc'
87
import formatCode from 'docs/src/utils/formatCode'
98

109
const rootStyle = {
@@ -144,4 +143,4 @@ class ComponentExampleRenderEditor extends PureComponent {
144143
}
145144
}
146145

147-
export default updateForKeys(['error', 'value'])(ComponentExampleRenderEditor)
146+
export default ComponentExampleRenderEditor

docs/src/components/ComponentDoc/ComponentExample/ComponentExampleRenderSource.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import PropTypes from 'prop-types'
22
import React from 'react'
33
import SourceRender from 'react-source-render'
44

5-
import { updateForKeys } from 'docs/src/hoc'
65
import { babelConfig, externals } from './renderConfig'
76

87
const resolver = (importPath, { displayName }) => {
@@ -42,4 +41,4 @@ ComponentExampleRenderSource.propTypes = {
4241
sourceCode: PropTypes.string.isRequired,
4342
}
4443

45-
export default updateForKeys(['sourceCode'])(ComponentExampleRenderSource)
44+
export default React.memo(ComponentExampleRenderSource)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropEnum.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash'
22
import PropTypes from 'prop-types'
33
import React from 'react'
44

5-
import { updateForKeys } from 'docs/src/hoc'
65
import ComponentPropExtra from './ComponentPropExtra'
76
import ComponentPropToggle from './ComponentPropEnumToggle'
87
import ComponentPropValue from './ComponentPropEnumValue'
@@ -18,7 +17,9 @@ const ComponentPropEnum = ({ limit, showAll, toggle, type, values }) => {
1817
{exceeds && <ComponentPropToggle toggle={toggle} total={values.length} showAll={showAll} />}
1918

2019
<div>
21-
{_.map(sliced, value => <ComponentPropValue key={value}>{value}</ComponentPropValue>)}
20+
{_.map(sliced, (value) => (
21+
<ComponentPropValue key={value}>{value}</ComponentPropValue>
22+
))}
2223
{exceeds && !showAll && '...'}
2324
</div>
2425
</ComponentPropExtra>
@@ -37,4 +38,4 @@ ComponentPropEnum.propTypes = {
3738
values: PropTypes.array,
3839
}
3940

40-
export default updateForKeys(['showAll', 'type', 'values'])(ComponentPropEnum)
41+
export default React.memo(ComponentPropEnum)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropEnumToggle.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
33

4-
import { updateForKeys } from 'docs/src/hoc'
5-
64
const toggleStyle = {
75
cursor: 'pointer',
86
}
@@ -19,4 +17,4 @@ ComponentPropEnumToggle.propTypes = {
1917
total: PropTypes.number,
2018
}
2119

22-
export default updateForKeys(['showAll'])(ComponentPropEnumToggle)
20+
export default React.memo(ComponentPropEnumToggle)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropEnumValue.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
33

4-
import { neverUpdate } from 'docs/src/hoc'
5-
64
const spanStyle = {
75
display: 'inline-block',
86
paddingRight: '0.2em',
@@ -18,4 +16,6 @@ ComponentPropEnumValue.propTypes = {
1816
children: PropTypes.node,
1917
}
2018

21-
export default neverUpdate(ComponentPropEnumValue)
19+
const areEqual = () => true
20+
21+
export default React.memo(ComponentPropEnumValue, areEqual)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropFunctionSignature.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ from 'lodash'
22
import PropTypes from 'prop-types'
33
import React from 'react'
44

5-
import { neverUpdate } from 'docs/src/hoc'
65
import ComponentPropExtra from './ComponentPropExtra'
76

87
const descriptionStyle = {
@@ -20,7 +19,7 @@ const rowStyle = {
2019
flexDirection: 'row',
2120
}
2221

23-
const getTagType = tag => (tag.type.type === 'AllLiteral' ? 'any' : tag.type.name)
22+
const getTagType = (tag) => (tag.type.type === 'AllLiteral' ? 'any' : tag.type.name)
2423

2524
const ComponentPropFunctionSignature = ({ name, tags }) => {
2625
const params = _.filter(tags, { title: 'param' })
@@ -31,9 +30,9 @@ const ComponentPropFunctionSignature = ({ name, tags }) => {
3130
if (_.isEmpty(params) && !returns) return null
3231

3332
const paramSignature = params
34-
.map(param => `${param.name}: ${getTagType(param)}`)
33+
.map((param) => `${param.name}: ${getTagType(param)}`)
3534
// prevent object properties from showing as individual params
36-
.filter(p => !_.includes(p, '.'))
35+
.filter((p) => !_.includes(p, '.'))
3736
.join(', ')
3837

3938
const tagDescriptionRows = _.compact([...params, returns]).map((tag) => {
@@ -66,4 +65,6 @@ ComponentPropFunctionSignature.propTypes = {
6665
tags: PropTypes.array,
6766
}
6867

69-
export default neverUpdate(ComponentPropFunctionSignature)
68+
const areEqual = () => true
69+
70+
export default React.memo(ComponentPropFunctionSignature, areEqual)

docs/src/components/ComponentDoc/ComponentProp/ComponentPropHeader.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import PropTypes from 'prop-types'
33
import React from 'react'
44
import { Menu } from 'semantic-ui-react'
55

6-
import { updateForKeys } from 'docs/src/hoc'
7-
86
const ComponentPropsComponents = ({
97
activeDisplayName,
108
displayNames,
@@ -15,7 +13,7 @@ const ComponentPropsComponents = ({
1513

1614
return (
1715
<Menu color='green' compact size='small' secondary>
18-
{_.map(displayNames, displayName => (
16+
{_.map(displayNames, (displayName) => (
1917
<Menu.Item
2018
key={displayName}
2119
active={activeDisplayName === displayName}
@@ -39,4 +37,8 @@ ComponentPropsComponents.propTypes = {
3937
parentDisplayName: PropTypes.string.isRequired,
4038
}
4139

42-
export default updateForKeys(['activeDisplayName', 'parentDisplayName'])(ComponentPropsComponents)
40+
const areEqual = (prevProps, nextProps) =>
41+
prevProps.activeDisplayName === nextProps.activeDisplayName &&
42+
prevProps.parentDisplayName === nextProps.parentDisplayName
43+
44+
export default React.memo(ComponentPropsComponents, areEqual)

0 commit comments

Comments
 (0)