Utilize the active tabpanel MUI component with Next.js router integration

Trying to implement active tab functionality using router pid

This is how it's done:

function dashboard({ tabId }) {

    const classes = useStyles();

    const [value, setValue] = React.useState(""); 

    useEffect(() => {
        console.log(tabId)
        if (tabId) {
            setValue(tabId);
        }

    }, [])
 
.......
}

Each TabPanel has a custom value that I'm trying to pass as the router parameter (pid)

The pid is obtained through getInitialProps

dashboard.getInitialProps = async ({ query }) => {
    if (!query.pid) {
        return { tabId: 0 }
    }
    return { tabId: query.pid }
}

The issue lies in the fact that the tab is set as active but its content is not displayed... Only the tab is marked as active...

Tabs/TabPanel

<Tabs value={value} 
                            onChange={handleChange} 
                            initialSelectedIndex={1}
                            variant="fullWidth" 
                            aria-label="simple tabs example"
                            TabIndicatorProps={{
                                style: {
                                    display:'none',
                                }
                            }}
                            >
                        <Tab label="HOME" value={0} />
                        <Tab label="MANAGE COLLECTION" value={1} />
                     .........
                        </Tabs>
                    </AppBar >

                    <TabPanel value={0} index={0}>

                    

                    </TabPanel>




                    <TabPanel value={1} index={1}>

                    </TabPanel>
     ......
                        
function TabPanel(props) {
    const { children, value, index, ...other } = props;
  
    return (
      <div
        role="tabpanel"
        hidden={value !== index}
        id={`simple-tabpanel-${index}`}
        aria-labelledby={`simple-tab-${index}`}
        {...other}
      >
        {value === index && (
          <Container>
          <Box p={3}>
            {children}
          </Box>
          </Container>
        )}
      </div>
    );
  }
  
  TabPanel.propTypes = {
    children: PropTypes.node,
    index: PropTypes.any.isRequired,
    value: PropTypes.any.isRequired,
  };
  


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

Any assistance would be greatly appreciated :)


Issue resolved by juliomalves

The problem was caused because of using string value instead of value={index}

Answer №1

Resolved by juliomalves

The issue was caused by mistakenly using a string value instead of value={index}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Graph is vanishing while linked

A unique HTML canvas is included in a standalone file called dashboard.html. To display the dashboard on the main homepage (home.html), we utilize ng-view nested within an ng-if directive. Oddly, clicking on the hyperlink "#" from the home page causes th ...

The jQuery form validator doesn't seem to work with AJAX for me, but I've figured out how to make jQuery validate without using

I have been facing an issue with my code that involves the jquery validator and ajax. The code seems to validate properly and the serialize() function appears to be working as I can see the data in the browser. However, the problem arises when the data d ...

What is the best way to post an image using nodejs and express?

Recently, I've been working on a CMS for a food automation system and one feature I want to incorporate is the ability to upload pictures of different foods: <form method="post" enctype="multipart/form-data" action="/upload"> <td>< ...

Find the Time Difference in IST using JavaScript

Is there a way to calculate the time difference between two different time zones in javascript? var startTime = doc.data().startTime; output: Fri Dec 06 2019 19:00:00 GMT+0530 (India Standard Time) var currentTime = new Date(Date.now()).toString(); outpu ...

Google Places Autocomplete with Angular 4 Material Design Integration

I'm looking to incorporate Google Places (autocomplete field) into my Angular 4/5 app that is styled using the Material UI framework. While I did come across a module here, it doesn't quite meet my needs as I am unable to style the input box wit ...

The AJAX session is triggered twice, without displaying an alert the second time

Upon loading the page, an AJAX session is triggered and then again after clicking. Strangely, the readystate change is not happening the second time around. To troubleshoot, I added an alert box in the function which appears during page load but not on cli ...

Guide to switching classes with jquery

On my webpage, I have a star rating system that I want to toggle between "fa fa-star" and "fa fa-star checked" classes. I found some information on how to do this here: Javascript/Jquery to change class onclick? However, when I tried to implement it, it di ...

Creating a custom component that encapsulates a TextField

I implemented a custom component that adds a '*' at the beginning of any typed text. Here is the code for this component: export default class MyTextField extends Component { constructor() { super(); this.state = { value: & ...

Access the contents of the selected cell in the MUI datagrid

When I choose a row from the datagrid, my attempt to access each cell value in that row always returns "undefined" when using selectedRowData.email. How can I correctly retrieve the data from a selected row's cells? <DataGrid checkboxSe ...

Organize express controller by breaking it up into multiple separate files

Recently, I've set up an express js controller file as follows The File Path: /controllers/usersController.js // Register User module.exports.register = function(req, res) { ... } // Login User module.exports.login = function(req, res) { ... } // ...

What seems to be the issue with the useState hook in my React application - is it not functioning as

Currently, I am engrossed in a project where I am crafting a Select component using a newfound design pattern. The execution looks flawless, but there seems to be an issue as the useState function doesn't seem to be functioning properly. As a newcomer ...

The Google Picker API encounters a server error when attempting to retrieve the OAuth token after being released as a private add-on

Recently, I encountered a puzzling issue with my script that utilizes the Google Picker API. During testing, everything worked flawlessly until I decided to publish it as a private add-on. From that point on, the script's getOAuthToken function starte ...

initiate a page refresh upon selecting a particular checkbox

So I've got this code that saves around 30 checkbox selections to local storage, which is working fine. Then there's this separate checkbox below, when checked it automatically reloads the page: <input type="checkbox" id="autoload" class="aut ...

I am seeking to perform these operations solely using pure WebGL, without relying on the Three.js library

if( keyboard.pressed("up")) pobjects[movementControls.translate].translateX(1); if( keyboard.pressed("down")) pobjects[movementControls.translate].translateX(-1); if( keyboard.pressed("left")) pobjects[mo ...

search through an object to find specific data

Here is a JavaScript object that I have: var data = { "type": [ "car", "bike" ], "wheels": [ "4", "2" ], "open": [ "Jan", "Jan" ] ...

The browser context has detected several instances of GoTrueClient running concurrently

I've been working on a project using nextjs and supabase. Unexpectedly, I'm seeing this warning message in the console: Multiple GoTrueClient instances detected in the same browser context. It's not an error, but it's best to avoid a ...

adding <script> elements directly before </body> tag produces unexpected results

While following a tutorial, the instructor recommended adding <script> tags right before the </body> to enhance user experience. This way, the script will run after the entire page content is loaded. After implementing the code block as sugges ...

What steps do I need to take to run my Angular project locally using globally installed npm packages?

I'm interested in maintaining all my packages globally, similar to how node package itself operates. For instance, if I have a package named "Highcharts" listed in my package.json file, I prefer to install it globally instead of creating a local node_ ...

Exploring the functionality of the readline module using a simulated command-line

I am currently working on developing a unit test for a module that utilizes the "readline" functionality to interpret standard input and provide standard output. Module: #!/usr/bin/env node const args = process.argv.slice(2) var readline = require(' ...

Menu rollout problem when clicking or hovering

I'm facing challenges in making my menu content appear when a user clicks or hovers over the hamburger menu. My app is built using Angular, and I've written some inline JavaScript and CSS to achieve this, but the results are not as expected. Here ...