Skip to content

Commit

Permalink
fix: immediately update with current component to handle initial badg…
Browse files Browse the repository at this point in the history
…e value (#4238)
  • Loading branch information
hacke2 authored Dec 17, 2024
1 parent eb3dfcb commit 5b6cc1b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/main-layout/src/browser/tabbar/bar.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,16 @@ export const IconTabView: React.FC<{ component: ComponentRegistryProvider }> = (
}, [component]);

useEffect(() => {
// Immediately update with current component to handle initial badge value
setComponent({ ...component });

const dispose = component.onChange((newComponent) => {
setComponent(newComponent);
});
return () => {
dispose.dispose();
};
}, []);
}, [component]); // Add component as dependency to re-run effect when it changes

return (
<div className={styles_icon_tab}>
Expand All @@ -246,12 +249,13 @@ export const TextTabView: React.FC<{ component: ComponentRegistryProvider }> = (
const [component, setComponent] = React.useState<ComponentRegistryProvider>(defaultComponent);
useEffect(() => {
const dispose = component.onChange((newComponent) => {
setComponent(newComponent);
// Immediately update with current component to handle initial badge value
setComponent({ ...newComponent });
});
return () => {
dispose.dispose();
};
}, []);
}, [component]); // Add component as dependency to re-run effect when it changes
return (
<div className={styles.text_tab}>
<div className={styles.bottom_tab_title}>{component.options?.title?.toUpperCase()}</div>
Expand Down

0 comments on commit 5b6cc1b

Please sign in to comment.