Skip to content

Commit

Permalink
components: Stop auto-memo antipattern and remove senseless default v…
Browse files Browse the repository at this point in the history
…alues (#31246)

* components: Stop auto-memo antipattern and remove senseless default values

* Update unit tests
  • Loading branch information
sarayourfriend authored Apr 28, 2021
1 parent c2a2c5e commit d2da787
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/ui/context/context-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import { getStyledClassNameFromKey } from './get-styled-class-name-from-key';
* @param {(props: P, ref: import('react').Ref<any>) => JSX.Element | null} Component The component to register into the Context system.
* @param {string} namespace The namespace to register the component under.
* @param {Object} options
* @param {boolean} [options.memo=true]
* @param {boolean} [options.memo=false]
* @return {import('./polymorphic-component').PolymorphicComponent<import('./polymorphic-component').ElementTypeFromViewOwnProps<P>, import('./polymorphic-component').PropsFromViewOwnProps<P>>} The connected PolymorphicComponent
*/
export function contextConnect( Component, namespace, options = {} ) {
/* eslint-enable jsdoc/valid-types */
const { memo: memoProp = true } = options;
const { memo: memoProp = false } = options;

let WrappedComponent = forwardRef( Component );
if ( memoProp ) {
Expand Down
7 changes: 3 additions & 4 deletions packages/components/src/ui/utils/create-component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { identity } from 'lodash';
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';
import type { As } from 'reakit-utils/types';
Expand Down Expand Up @@ -41,9 +40,9 @@ export const createComponent = <
P extends ViewOwnProps< {}, A >
>( {
as,
name = 'Component',
useHook = identity,
memo = true,
name,
useHook,
memo = false,
}: Options< A, P > ): PolymorphicComponent<
ElementTypeFromViewOwnProps< P >,
PropsFromViewOwnProps< P >
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/ui/utils/test/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe( 'createComponent', () => {
as: 'output',
name,
useHook,
memo: true,
} );
const Output = createComponent( {
as: 'output',
Expand All @@ -40,7 +41,7 @@ describe( 'createComponent', () => {
expect( container.firstChild.innerHTML ).toBe( 'Example output' );
} );

it( 'should create a memoized, ref-forwarded component by default', () => {
it( 'should create a memoized, ref-forwarded component', () => {
expect( MemoizedOutput.$$typeof ).toEqual( Symbol.for( 'react.memo' ) );
const ref = createRef();
const wrapper = render(
Expand Down

0 comments on commit d2da787

Please sign in to comment.