<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: iMalFect</title>
    <description>The latest articles on Forem by iMalFect (@imalfect).</description>
    <link>https://forem.com/imalfect</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F985396%2Febfb8877-0f8b-470e-91ac-5e08d05f3e76.png</url>
      <title>Forem: iMalFect</title>
      <link>https://forem.com/imalfect</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/imalfect"/>
    <language>en</language>
    <item>
      <title>Why aren't my tabs switching?</title>
      <dc:creator>iMalFect</dc:creator>
      <pubDate>Tue, 06 Dec 2022 15:02:11 +0000</pubDate>
      <link>https://forem.com/imalfect/why-arent-my-tabs-switching-4mbb</link>
      <guid>https://forem.com/imalfect/why-arent-my-tabs-switching-4mbb</guid>
      <description>&lt;p&gt;Hello, I've recently made a react component, and my Material UI tabs aren't switching properly, I've attached a video for you to see the issue. If I put the tabs manually, it all works just fine.&lt;br&gt;
Video: &lt;a href="https://streamable.com/heugq4" rel="noopener noreferrer"&gt;https://streamable.com/heugq4&lt;/a&gt;&lt;br&gt;
My component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from 'react';
import PropTypes from 'prop-types';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import NamePanel from "./NamePanel.jsx";
import {PayClient} from "../Offchain.js";
import * as ViteConnect from "../ViteConnect.js"
import {useEffect} from "react";
function TabPanel(props) {
    const { children, value, index, ...other } = props;

    return (
        &amp;lt;div
            role="tabpanel"
            hidden={value !== index}
            id={`simple-tabpanel-${index}`}
            aria-labelledby={`simple-tab-${index}`}
            {...other}
        &amp;gt;
            {value === index &amp;amp;&amp;amp; (
                &amp;lt;Box sx={{ p: 3 }}&amp;gt;
                    &amp;lt;Typography&amp;gt;{children}&amp;lt;/Typography&amp;gt;
                &amp;lt;/Box&amp;gt;
            )}
        &amp;lt;/div&amp;gt;
    );
}

TabPanel.propTypes = {
    children: PropTypes.node,
    index: PropTypes.number.isRequired,
    value: PropTypes.number.isRequired,
};

function a11yProps(index) {
    return {
        id: `simple-tab-${index}`,
        'aria-controls': `simple-tabpanel-${index}`,
    };
}

export default function ManageNameTabs() {

    const [value, setValue] = React.useState(0);
    const [tabs, setTabs] = React.useState('e');
    const [tabPanels, setTabPanels] = React.useState([]);
    const [namesArray, setNamesArray] = React.useState([]);
    useEffect(() =&amp;gt; {
        async function run() {
            const connectedAddress = ViteConnect.getConnectedAddress()
            const names = await PayClient.getNamesByAddress(connectedAddress);
            let tabs = [];
            let tabPanels = [];
            let currentIndex = 0;

            for (const name of names) {
                console.log(name)
                tabPanels.push(
                    &amp;lt;TabPanel value={value} index={currentIndex} key={name.nameId} &amp;gt;
                        &amp;lt;NamePanel name={name.name} nameId={name.nameId} owner={connectedAddress}
                                   isVerified={name.isTrusted} key={name.nameId}/&amp;gt;
                    &amp;lt;/TabPanel&amp;gt;
                )

                tabs.push(&amp;lt;Tab label={name.name + ".vinu"} {...a11yProps(currentIndex)} key={name.nameId}/&amp;gt;)
                currentIndex++;
            }
            setTabPanels(tabPanels);
            setTabs(tabs);
        }
        run()
    }, [])

    const handleChange = (event, newValue) =&amp;gt; {
        setValue(newValue);
    };




    return (
        &amp;lt;Box sx={{ width: '100%' }}  component="div"&amp;gt;
            &amp;lt;Box sx={{ borderBottom: 1, borderColor: 'divider', maxWidth: { xs: 320, sm: 480, md: 600, lg: 900}, minWidth: {xs: 200, sm: 300, md: 400, lg: 800}}} component="div"&amp;gt;
                &amp;lt;Tabs value={value} onChange={handleChange} aria-label="basic tabs example" variant="scrollable" scrollButtons="auto"&amp;gt;
                    {tabs}
                &amp;lt;/Tabs&amp;gt;
            &amp;lt;/Box&amp;gt;
            {tabPanels}
        &amp;lt;/Box&amp;gt;
    );


}        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
