Skip to content
Advertisement

Show/Hide Component by passing useState Value React

I’m building a website with React and Bootstrap which would have a static footer. The footer will contain two buttons – Back, and Next. Clicking ‘back’ decrements an index, and clicking ‘next’ would increment the index. Ideally this index would keep track of which js component to show or hide using a ternary statement with with display: ‘inline’ or ‘none’. I’ve tried useState in the App.js file, AND in the Footer.js file, but I am unable to pass the useState values between components it seems. Is there a better way to do this? I have provided some of my code which does not work.

Footer.js:

JavaScript

App.js:

JavaScript

Advertisement

Answer

Few issues with your code: 1) className, not the class in react. 2) Error in your onClick parameters. 3) You need to move state up to the App component.

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