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

Utilizing the "return" keyword in Javascript outside of function declarations

Exploring the Impact of Using the Return Keyword in JavaScript Scripts Beyond Functions in Browsers and Node.js Recently, I experimented with utilizing the return keyword in a Node.js script like so: #!/usr/bin/env node return 10; My initial assumption ...

The image in drag and drop ghost preview is not appearing on Firefox

I want to show a ghost element instead of the default browser preview while dragging and dropping. However, in Firefox, the image inside the ghost element is not displayed during dragging. Oddly enough, if I drop it and then drag again, the image does appe ...

Transform the code provided by bundleMDX into an HTML string specifically for RSS, all the while utilizing the mdx-bundler

I am currently working on developing an RSS reader and I need to convert the code returned by bundleMDX into a string. This is necessary so that I can utilize it with ReactDOMServer.renderToStaticMarkup(mdx) in my project. You can find a similar implement ...

"Transforming JSON data into a format compatible with Highcharts in PHP: A step-by-step

Currently facing an issue with converting the given array format into a Highcharts compatible JSON to create a line chart. Although everything else is functioning correctly, I am struggling with this specific conversion task. { name: [ 1000, ...

Storing user authentication tokens securely in session storage within Next.js can help maintain a

Is there a way to ensure that user data remains persistent even after a page refresh? I considered storing it in local storage, but that may result in a flash of unauthenticated content. Storing it in a cookie could also be problematic when working with ...

Execute the function when the form is submitted and show the total of the two values

I am currently working on a straightforward custom module for Drupal 7. This module takes two numeric values and upon submission, displays the sum of these values on the same page. While I have the form set up, it is not yet complete. I am facing some dif ...

Unable to add chosen elements to array - Angular material mat select allowing multiple selections

Can anyone assist me in figuring out what I am doing wrong when attempting to push data to an empty array? I am trying to only add selected values (i.e. those with checked as true), but I can't seem to get inside the loop This is the current conditi ...

When using nextjs, there is an issue that arises when attempting to define the property 'id' using context.params.id. This results in

Attempting to retrieve data from a JSON file (response.json) hosted on localhost:8000/response.json. Below is the code snippet from pages/test.js: import React from "react"; import Link from "next/link"; import Image from "next/ima ...

What is the best way to eliminate the default active background color in ReactNative Material Bottom Tabs version 6.2.10?

Can someone help me figure out how to remove the background color from the image linked below? I've tried various properties in the documentation but nothing seems to work. https://i.stack.imgur.com/mD8gW.png ...

Issue with disabling elements using jQuery in IE 10

I'm encountering a problem with using attr('disabled', 'disabled') or prop("disabled", true) in Internet Explorer when using jQuery. This works fine in Firefox and Chrome but not in IE. Any suggestions? I'm attempting to disa ...

Creating a form with multiple checkboxes using Material-UI components where only a single checkbox can be selected

Creating a simple form using Material-UI with checkboxes to select one option and push data to the backend on submit is the goal. The Form component structure includes: multiple options represented by checkboxes only one checkbox can be selected at a time ...

Disable system discord.js

Hey there, I'm experiencing an issue with my code and could use some help. Every time I try to use my mute command, it keeps spamming "You need permission to use command". Below is the snippet of my code: client.on('message', message => { ...

How can I implement a jQuery slide down effect for a specific individual instance?

Whenever I click on the "Share your thoughts" button, the comments block slides down for every section instead of just the particular section I clicked on. Is there a way to make it so that only a single block slides down when the button is clicked, regard ...

Next.js app experiencing issues with Chakra UI not transitioning to dark mode

After attempting to incorporate Chakra UI into my Next.js application, I carefully followed every step outlined in their documentation: Despite setting the initialColorMode to "dark" for the ColorModeScript prop, it seems that the dark mode is not being a ...

When I select an option with an object, ng-model is receiving '[object Object]' instead of the actual object for <select> element

Referencing an example from Angular documentation: this link, specifically the section on "Using ngValue to bind the model to an array of objects." In the index.html file: <!doctype html> <html lang="en"> <head> <meta charset="UTF- ...

Detecting collisions between two squares in an HTML5 canvas

class Snake { constructor() { this.x = 400; this.y = 400; this.width = 25; this.height = 25; } draw() { ctx.fillRect(this.x, this.y, this.width, this.height); } } let snake = new Snake(); class ...

Encountering build issues in my next.js application post updating to version 12.#.# and implementing Typescript

In my next.js application, I recently upgraded to version 10 and added TypeScript to the mix. Despite ironing out all issues during development, I encountered errors when running yarn next build due to my use of the keyword interface. ./src/components/ ...

The Webstorm AngularJS extension appears to be malfunctioning, as it is not able to recognize the keyword 'angular'

As a beginner in Angularjs and web development, I have been using Webstorm to develop my projects. I have already installed the Angularjs plugin, which seems to be working fine in my HTML files. However, I am facing an issue with my .js file. In this file, ...

CAUTION: Attempted to initialize angular multiple times...all because of jQuery...such a puzzling issue, isn

I am attempting to comprehend the situation at hand. The warning is clear, and I acknowledge that in my application, with the provided code and structure, the ng-view runs twice ('test' is logged twice in the console, indicating that angular is l ...

What are the steps for conducting a component test with material ui?

My current component is built using . import React from 'react'; import { AppBar, Toolbar } from 'material-ui'; import { Typography } from 'material-ui'; import { MuiThemeProvider, createMuiTheme } from 'material-ui/sty ...