0

I have a component of header in react and in the same way a component of tabs in another file. I integrate them in app.js . Now I want to change the tabs on click of the header buttons. How could it been possible can anyone help me in this regard.

I have tried it through giving an ID to the tabs and tried to open the tab by calling that ID in href using anchor tag around the tab buttons. But this way can't help me in to open tabs. https://codesandbox.io/embed/shy-grass-l9n7m

5
  • Could you please share your code ? Commented Oct 16, 2019 at 11:15
  • I have pushed on heroku I can provide you the remote origin link you can clone the project from there. Can it help you? Commented Oct 16, 2019 at 11:19
  • Can you add a small code example? Codesandbox? Commented Oct 16, 2019 at 11:19
  • you have something called state in react , use state to switch see this: upmostly.com/tutorials/… Commented Oct 16, 2019 at 12:47
  • I agree, I'd remove jQuery and just use react component state to conditionally render content. I've submitted an answer with a little more detail and a very rough proof of concept on how to apply it to the code. Commented Oct 16, 2019 at 13:11

1 Answer 1

1

I noticed you are using jQuery to set the tab value. I suggest using React for that with something more like this: https://codesandbox.io/embed/morning-water-dit63

Note: The above code is very rough because I just through it together by modifying your code. For example, I used the active and fade class names to set the visibility of tab content where personally I might have done conditional rendering like this:

render (
  // tabs
  {this.isActive('home') && (
    // tab content here
  )}
)

Alternatively you could use a library to handle it like https://reactcommunity.org/react-tabs/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.