Skip to content

Commit

Permalink
fix: use primitive type in useEffect for query param updates to reduc…
Browse files Browse the repository at this point in the history
…e executions
  • Loading branch information
harshpatel-crest committed Mar 31, 2021
1 parent 9c5cc2f commit a4a0542
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function CustomTable({
useEffect(() => {
// Only run when tab matches serviceName or if in input page where serviceName is undefined
if (query && (query.get('tab') === serviceName || typeof serviceName === 'undefined')) {
// Open modal when record is available in query param and modal is not open
// Open modal when record is available in query params and modal is not open
if (query.get('record') && !entityModal.open) {
const row = data.find((x) => x.name === query.get('record'));
setEntityModal({
Expand All @@ -61,12 +61,14 @@ function CustomTable({
stanzaName: row.name,
mode: MODE_EDIT,
});
// Close modal if record query param is not available and mode is edit
} else if (!query.get('record') && entityModal.open && entityModal.mode === MODE_EDIT) {
// Close modal if record query param is not available and modal is open
// NOTE: This should only be executed in case of MODE_EDIT which is handled by
// useEffect dependency
} else if (!query.get('record') && entityModal.open) {
setEntityModal({ ...entityModal, open: false });
}
}
}, [query]);
}, [history.location.search]);

const generateColumns = () => {
const column = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ConfigurationPage() {
) {
setActiveTabId(query.get('tab'));
}
}, [query]);
}, [history.location.search]);

const handleChange = (e, { selectedTabId }) => {
setActiveTabId(selectedTabId);
Expand Down

0 comments on commit a4a0542

Please sign in to comment.