Giter VIP home page Giter VIP logo

Comments (2)

joepvl avatar joepvl commented on July 20, 2024 1

Hi. Unfortunately there is no way to declare your TabPanels in a separate component; the Tabs component can't detect them through the component boundary. However, a simple solution in this case would be to turn the Tables and Graphs components into render functions:

function renderTables() {
  return (
    <React.Fragment>
      <TabPanel>Table content 1</TabPanel>
      <TabPanel>Table content 2</TabPanel>
    </React.Fragment>
  );
}

function renderGraphs() {
  return (
    <React.Fragment>
      <TabPanel>Graph content 1</TabPanel>
      <TabPanel>Graph content 2</TabPanel>
    </React.Fragment>
  );
}

function AppTabs({ mode }) {
  return (
    <Tabs className="tabs">
      <TabList>
        <Tab>title 1</Tab>
        <Tab>title 2</Tab>
      </TabList>
      {mode === 'tables' && renderTables()}
      {mode === 'graphs' && renderGraphs()}
    </Tabs>
  );
}

Another way to solve this particular issue would be to pass the mode to the components you render inside the TabPanels and use that to decide what to render from inside the component.

from react-tabs.

mariela-plaza avatar mariela-plaza commented on July 20, 2024

Hi joepvl, thank you for your answer!
The code I provided is from a pet project that simplifies what I want to achieve in the real project I am working on.

The issue is that in this real project, the Tables and Graphs component would have their own states and a lot of complex logic that would unique to each one. That is why I can't turn them into render functions.

I also thought about implementing the second solution you suggested, but that would mean that all of the states and complex logic that I want to use in the Tables and Graphs components would need to be declared in the AppTabs component, which would make said component quite cluttered and difficult to work with.

I appreciate very much your input, it gives me a lot more clarity on what I can do and can't do with the project at hand :)
Have a great day, kind regards!

from react-tabs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.