Skip to content

Commit

Permalink
Fix replaceWith passing extra props to Fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-varela committed Apr 11, 2022
1 parent 295af9a commit bb4f47e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/fclasses/src/replaceable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import React, {
useContext,
useState,
useEffect,
Fragment,
} from 'react';
import pick from 'lodash/pick';
import { HOCBase, ComponentOrTag, HOC } from './types';
import { flowHoc } from './flowHoc';

Expand Down Expand Up @@ -103,7 +105,10 @@ export const startWith = (ReplacementComponent: ComponentType<any>): HOCBase =>

export const replaceWith = <P extends object>(Replacement: ComponentOrTag<P>) => flowHoc(
(() => {
const ReplaceWith = (props: P) => <Replacement {...props} />;
const ReplaceWith = (props: P) => {
const $props = Replacement === Fragment ? pick(props, 'key', 'children') : props;
return <Replacement {...$props as P} />;
};
return ReplaceWith;
}) as HOC
);
Expand Down

0 comments on commit bb4f47e

Please sign in to comment.