Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
refactor: trigger re-render on components change
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlahti committed Aug 8, 2023
1 parent b83fb90 commit bdc0949
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const stylingPanelDef = {
items: {
headerItems: {
component: 'items',
ref: 'components',
key: 'listBox',
items: {
fontWrapperItem: {
Expand Down Expand Up @@ -59,6 +60,7 @@ const stylingPanelDef = {
items: {
contentItems: {
component: 'items',
ref: 'components',
key: 'listBox',
items: {
contentFontWrapper: {
Expand Down
1 change: 1 addition & 0 deletions packages/sn-filter-pane/src/hooks/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface IFilterPaneLayout {
layoutOptions?: {
compactData?: boolean,
}
components?: object[],
}

export interface IListboxResource {
Expand Down
6 changes: 5 additions & 1 deletion packages/sn-filter-pane/src/hooks/use-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default function useRender(stores: IStores) {
});
}

// Trigger a re-render only when components have changed in the filterpane layout.
// (Note that useEffect equality check is shallow and therefore requires a hash.)
const componentsHash = (fpLayout?.components || []).map((c: object) => JSON.stringify(c)).join(',');

useEffect(() => {
if (!fpLayout || !app || !resourcesReady) {
return undefined;
Expand All @@ -27,5 +31,5 @@ export default function useRender(stores: IStores) {
return (() => {
teardown(root);
});
}, [resourcesReady, fpLayout]);
}, [resourcesReady, componentsHash]);
}

0 comments on commit bdc0949

Please sign in to comment.