Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Toggle Visibility with State | Section
React Basics for Next

bookChallenge: Toggle Visibility with State

メニューを表示するにはスワイプしてください

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

  1. Import the useState hook from the React library.
  2. Declare a state variable named isVisible using the useState hook. Initialize it with the value false.
  3. Implement a function named toggleVisibility that, when called, toggles the isVisible state between true and false.
  4. Use the toggleVisibility function as the onClick handler for the button.
  1. Include an import statement to import the appropriate hook from the React library.
  2. For this task, we will utilize the useState hook as we are managing the state of paragraph visibility.
  3. To determine the appropriate variable name for the state, observe the function associated with setting the state, which is setIsVisible. Remove the "set" prefix and use a lowercase first letter for the variable name, which should be isVisible.
  4. To invoke the toggleVisibility function when the button is clicked, assign it as the value for the onClick attribute of the button.

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  15

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  15
some-alt