Skip to content
Advertisement

Change style of the text dynamically React js

I want to change some styles of the text of the tab for my navbar. I want to switch between pages whenever I click the on the tab. And for that I want that tab to be active. I have written code as:

Header.js

JavaScript

Header.css

JavaScript

Tab.js

JavaScript

Tab.css

JavaScript

Now when I click the tab it becomes active and clicking another tab make both of them active but I want only one to be active. How can I change the code in order to achieve what I want?

Advertisement

Answer

You have to lift the active tab state from the Tab component to the Header one and set a callback that will be passed to the Tab component, in order to update the state in the parent.

You should end up with something like:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement