Challenge: Toggle Visibility with useState
Task
Create a component that includes a button and a text paragraph. Implement the necessary logic using the useState
hook to toggle the visibility of the text paragraph when the button is clicked.
Instructions
- Import the
useState
hook from the React library. - Declare a state variable named
isVisible
using theuseState
hook. Initialize it with the valuefalse
. - Implement a function named
toggleVisibility
that, when called, toggles theisVisible
state betweentrue
andfalse
. - Use the
toggleVisibility
function as theonClick
handler for the button.
Thanks for your feedback!