Skip to content

Commit 7043e2c

Browse files
committed
fix: fixed issue with component update
1 parent 56f3791 commit 7043e2c

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

components/react-alt/src/Particles.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ export default class Particles extends Component<IParticlesProps, IParticlesStat
4141
}
4242

4343
shouldComponentUpdate(nextProps: Readonly<IParticlesProps>): boolean {
44+
const nextOptions = nextProps.options ?? nextProps.params,
45+
currentOptions = this.props.options ?? this.props.params;
46+
4447
return (
45-
nextProps.url !== this.props.url &&
46-
nextProps.id !== this.props.id &&
47-
nextProps.canvasClassName !== this.props.canvasClassName &&
48-
nextProps.className !== this.props.className &&
49-
nextProps.height !== this.props.height &&
50-
nextProps.width !== this.props.width &&
51-
!deepCompare(nextProps.style, this.props.style) &&
52-
nextProps.init !== this.props.init &&
53-
nextProps.loaded !== this.props.loaded &&
54-
!deepCompare(nextProps.options ?? nextProps.params, this.props.options && this.props.params)
48+
nextProps.url !== this.props.url ||
49+
nextProps.id !== this.props.id ||
50+
nextProps.canvasClassName !== this.props.canvasClassName ||
51+
nextProps.className !== this.props.className ||
52+
nextProps.height !== this.props.height ||
53+
nextProps.width !== this.props.width ||
54+
!deepCompare(nextProps.style, this.props.style) ||
55+
nextProps.init !== this.props.init ||
56+
nextProps.loaded !== this.props.loaded ||
57+
!deepCompare(nextOptions, currentOptions, key => key.startsWith("_"))
5558
);
5659
}
5760

components/react-alt/src/Utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export function deepCompare(
1717
}
1818

1919
for (const key of keys1) {
20-
console.log("key");
21-
2220
const value1: unknown = (obj1 as Record<string, unknown>)[key],
2321
value2: unknown = (obj2 as Record<string, unknown>)[key];
2422

components/react/src/Particles.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ export default class Particles extends Component<IParticlesProps, IParticlesStat
4141
}
4242

4343
shouldComponentUpdate(nextProps: Readonly<IParticlesProps>): boolean {
44+
const nextOptions = nextProps.options ?? nextProps.params,
45+
currentOptions = this.props.options ?? this.props.params;
46+
4447
return (
45-
nextProps.url !== this.props.url &&
46-
nextProps.id !== this.props.id &&
47-
nextProps.canvasClassName !== this.props.canvasClassName &&
48-
nextProps.className !== this.props.className &&
49-
nextProps.height !== this.props.height &&
50-
nextProps.width !== this.props.width &&
51-
!deepCompare(nextProps.style, this.props.style) &&
52-
nextProps.init !== this.props.init &&
53-
nextProps.loaded !== this.props.loaded &&
54-
!deepCompare(nextProps.options ?? nextProps.params, this.props.options && this.props.params)
48+
nextProps.url !== this.props.url ||
49+
nextProps.id !== this.props.id ||
50+
nextProps.canvasClassName !== this.props.canvasClassName ||
51+
nextProps.className !== this.props.className ||
52+
nextProps.height !== this.props.height ||
53+
nextProps.width !== this.props.width ||
54+
!deepCompare(nextProps.style, this.props.style) ||
55+
nextProps.init !== this.props.init ||
56+
nextProps.loaded !== this.props.loaded ||
57+
!deepCompare(nextOptions, currentOptions, key => key.startsWith("_"))
5558
);
5659
}
5760

components/react/src/Utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export function deepCompare(
1717
}
1818

1919
for (const key of keys1) {
20-
console.log("key");
21-
2220
const value1: unknown = (obj1 as Record<string, unknown>)[key],
2321
value2: unknown = (obj2 as Record<string, unknown>)[key];
2422

0 commit comments

Comments
 (0)