UseState - Exercises
The article discusses various exercises using the React useState hook for beginners. It includes examples such as a toggle button, input field, character counter, and dependent dropdown. Each example demonstrates how to manage state in functional components effectively.
- ▪The Toggle component allows users to switch between an on and off state using images.
- ▪The Input component greets users by name as they type into a text field.
- ▪The Dependent component showcases how to create dropdowns that change based on previous selections.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3795010) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Sivakumar Mathiyalagan Posted on May 21 UseState - Exercises #beginners #javascript #react #tutorial *Toggle Button * import { useState } from "react"; function Toggle(){ const [bulb,setBulb] = useState("https://www.w3schools.com/js/pic_bulboff.gif") // const [flag,setFlag] = useState(false); function toggle(){ if (bulb === "https://www.w3schools.com/js/pic_bulboff.gif"){ setBulb("https://www.w3schools.com/js/pic_bulbon.gif") // setFlag(true); } else{…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).