简体   繁体   English

选项卡导航不显示。 (反应.JS / JS)

[英]Tab Navigation Not Displaying! (React.JS / JS)

I am trying to make tab navigation for a section on an app that I'm working on, though I am having some trouble.我正在尝试为我正在使用的应用程序的某个部分制作标签导航,但我遇到了一些麻烦。 It was working a while ago but for some reason, it's not displaying the different tabs to click on.它在一段时间前工作,但由于某种原因,它没有显示不同的选项卡来单击。

I am still fairly new to React and JS so I'm having a hard time following the code that I wrote before.我对 React 和 JS 还是很陌生,所以我很难理解我之前写的代码。 (also, I'm not sure why I am not using the HandleChange but I remember that I need it) (另外,我不确定为什么我不使用 HandleChange 但我记得我需要它)

Here is my code:这是我的代码:

import React from "react";
import InfoText from "./InfoComponent";
import TransportationText from "./TransportationComponent";
import Hotels from "./HotelsComponent";
import FAQ from "./FAQComponent";
import Covid from "./CovidComponent";


const TravelersTab = () => {
  const [selectedTab, setSelectedTab] = React.useState(0);
  
  const handleChange = (event, newValue) => {
    setSelectedTab(newValue);
  };

  return (
    <div 
    position="static"
    >
      <h1 style={{
        textAlign: "center"
      }}>Travelers</h1>
      
      {selectedTab === 0 && <InfoText />}
      {selectedTab === 1 && <Hotels />}
      {selectedTab === 2 && <TransportationText />}
      {selectedTab === 3 && <Covid />}
      {selectedTab === 4 && <FAQ />}
    </div>
  );
};

export default TravelersTab;

Here is a picture of what I am seeing:这是我所看到的图片: 它看起来像什么

If anyone has any information that would be helpful, that would be much appreciated: Thanks for taking the time to help me out!!如果有人有任何有用的信息,将不胜感激:感谢您抽出宝贵时间帮助我!! : ) :)

const TravelersTab = () => {
  const [selectedTab, setSelectedTab] = React.useState(0);
  
  const handleChange = (newValue) => {
    setSelectedTab(newValue);
  };

  return (
    <div 
    position="static"
    >
      <h1 style={{
        textAlign: "center"
      }}>Travelers</h1>
      
      {selectedTab === 0 && <InfoText onClick={handleChange(0)}/>}
      {selectedTab === 1 && <Hotels onClick={handleChange(1)}/>}
      {selectedTab === 2 && <TransportationText onClick={handleChange(2)}/>}
      {selectedTab === 3 && <Covid onClick={handleChange(3)}/>}
      {selectedTab === 4 && <FAQ onClick={handleChange(4)}/>}
    </div>
  );
};

And set onClick event on tabItem in each Tab component such as "InfoText, Hotels, TransportationText...." Of course this is not best practice, but it would be help.并在每个 Tab 组件(例如“InfoText、Hotels、TransportationText...”)的 tabItem 上设置 onClick 事件。当然,这不是最佳做法,但会有所帮助。
I can deliver some wonderful code snippet for this.我可以为此提供一些精彩的代码片段。
Please send me DM if you want it.如果需要,请发给我 DM。

~ Storm In Talent ~ 人才风暴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM