Skip to content

Commit 80fcf3c

Browse files
committed
avoid some mutation in the Incorporator
1 parent bf18a01 commit 80fcf3c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/incorporate.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class Incorporator extends PureComponent<Props, State> {
3030
super(props);
3131
this.state = {flip: false};
3232
this.selector = props.targetProps.sel;
33-
delete props.targetProps.sel;
3433
}
3534

3635
private selector: string | symbol;
@@ -51,13 +50,20 @@ export class Incorporator extends PureComponent<Props, State> {
5150
return props;
5251
}
5352

54-
public render() {
55-
const {target, targetProps, targetRef, scope} = this.props;
56-
this.incorporateHandlers(targetProps, scope);
53+
private materializeTargetProps() {
54+
const {targetProps, targetRef, scope} = this.props;
55+
let output = {...targetProps};
56+
output = this.incorporateHandlers(output, scope);
5757
if (targetRef) {
58-
targetProps.ref = targetRef;
58+
output.ref = targetRef;
5959
}
60-
delete targetProps.sel;
60+
delete output.sel;
61+
return output;
62+
}
63+
64+
public render() {
65+
const {target} = this.props;
66+
const targetProps = this.materializeTargetProps();
6167
if (targetProps.children) {
6268
return createElement(target, targetProps, targetProps.children);
6369
} else {
@@ -77,7 +83,7 @@ export function incorporate(type: any) {
7783
forwardRef<any, any>((props, ref) =>
7884
createElement(ScopeContext.Consumer, null, (scope: Scope) =>
7985
createElement(Incorporator, {
80-
targetProps: {...props},
86+
targetProps: props,
8187
targetRef: ref,
8288
target: type,
8389
scope: scope,

0 commit comments

Comments
 (0)