From 140455126c467e27ea9932432a5a5bd9f7a51761 Mon Sep 17 00:00:00 2001 From: Conan1985 Date: Fri, 11 Aug 2023 15:10:10 -0500 Subject: [PATCH] Fix change detection The nextProps could contain new objects but actually the exact value of old ones. Compare their values instead to make sure shouldComponentUpdate only triggered with actual change. --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 4c796b7..5460045 100644 --- a/src/index.js +++ b/src/index.js @@ -67,11 +67,11 @@ export default class Timeline extends Component { shouldComponentUpdate(nextProps) { const { items, groups, options, selection, customTimes } = this.props - const itemsChange = items !== nextProps.items - const groupsChange = groups !== nextProps.groups - const optionsChange = options !== nextProps.options - const customTimesChange = customTimes !== nextProps.customTimes - const selectionChange = selection !== nextProps.selection + const itemsChange = JSON.stringify(items) !== JSON.stringify(nextProps.items) + const groupsChange = JSON.stringify(groups) !== JSON.stringify(nextProps.groups) + const optionsChange = JSON.stringify(options) !== JSON.stringify(nextProps.options) + const customTimesChange = JSON.stringify(customTimes) !== JSON.stringify(nextProps.customTimes) + const selectionChange = JSON.stringify(selection) !== JSON.stringify(nextProps.selection) return ( itemsChange ||