Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/components/MdxTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
'use client';

import { Box, Tab, Tabs } from '@mui/material';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

interface Props {
children?: React.ReactNode;
}

export default function MdxTabs({ children }: Props) {
const [value, setValue] = useState<number | undefined>(0);
const items = Array.isArray(children) ? children : [];

const items = useMemo(
() => (Array.isArray(children) ? children : []),
[children],
);

const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
Expand All @@ -22,14 +26,16 @@ export default function MdxTabs({ children }: Props) {
if (activeIndex !== -1) {
setValue(activeIndex);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [items]);

return (
<>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={value} onChange={handleChange}>
{items.map((item, index) => {
if (!item?.props?.label) {
console.log(item);
}
return <Tab key={index} label={item?.props?.label} />;
})}
</Tabs>
Expand Down