Show and hide password in React

Today we are going to show you how to manage a show and hide password in React. In this short article, we’ll add the input password field to manage the show or hide functionality in ReactJS.

Here, we’ll not use any npm package to manage the show/hide password functionality.

Steps to show and hide password in React

  1. Create a react app
  2. Add password field in component
  3. Implement show/hide password functionality
  4. Output

1. Create a react app

Let’s create a startup react application using the create-react-app npm package. Run the following command to create a react application.

2. Add password field in component

Now, Let’s design an input password field in the react component. We’ll also add the show/hide image icon to manage the functionality.

App.js

index.css

3. Implement show/hide password functionality

To implement show/hide password functionality, we have to change the input type from password to the text and for that we will use the state variable. Also change the show/hide password image based on the same state variable.

App.js

4. Output

Run the react application and check the output in the browser.

Output - Show and hide password in React - Clue Mediator
Output – Show and hide password in React – Clue Mediator

That’s it for today.
Thank you for reading. Happy Coding..!!

Demo & Source Code

Github Repository StackBlitz Project
If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *