DEV Community

Cover image for toggle button with react
Simone Gentili
Simone Gentili

Posted on

3

toggle button with react

overview

I've created same post years ago in the same serie. Before I created 25 videos about react and some other about NextJs. Also, .. before meet vite. This is an updated version of an old article about toggle button creation with react.

requirements

You just need npm installed to run the following command



npm create vite@latest
cd app_name
npm install
npm run dev


Enter fullscreen mode Exit fullscreen mode

src/App.tsx

Replace src/App.tsx file with this:



import { useState } from 'react'
import './App.css'

function App() {
  const [pressed,setPressed] = useState(false)
  const label = pressed?'pressed':'unpressed'
  return (
    <>
      <h1>Toggle button</h1>
      <button onClick={() => setPressed(!pressed)}>{label}</button>
    </>
  )
}

export default App


Enter fullscreen mode Exit fullscreen mode

preview of toggle button

Conclusion

Study is better. Now React have hooks. Install with cdn is fine but create app with vite is cool.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay