Skip to content

Commit

Permalink
Merge pull request #210 from storybookjs/fix-renderers-dropdown
Browse files Browse the repository at this point in the history
Fix infinite loop list of renderers
  • Loading branch information
cdedreuille authored Jul 18, 2024
2 parents 68857c7 + 775003b commit 00c2b02
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions apps/frontpage/components/docs/renderers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ export const Renderers: FC = () => {
const [lastRenderer, setLastRenderer] = useState<Renderer>(renderers[3]);

useEffect(() => {
// On mobile we only show the first two renderers
if (isMobile) {
setFirstList(renderers.slice(0, 2));
setLastRenderer(renderers[2]);
} else {
setFirstList(renderers.slice(0, 3));
setLastRenderer(renderers[3]);
}

const isInFirstList = firstList.some(
(renderer) => renderer.id === activeRenderer,
);
Expand All @@ -43,6 +34,17 @@ export const Renderers: FC = () => {
}
}, [isMobile, activeRenderer, firstList]);

useEffect(() => {
// On mobile we only show the first two renderers
if (isMobile) {
setFirstList(renderers.slice(0, 2));
setLastRenderer(renderers[2]);
} else {
setFirstList(renderers.slice(0, 3));
setLastRenderer(renderers[3]);
}
}, [isMobile, activeRenderer]);

const restRenderers = renderers.filter((r) => {
return !firstList.includes(r) && r !== lastRenderer;
});
Expand Down

0 comments on commit 00c2b02

Please sign in to comment.