DEV Community

Mohammed Nadeem Shareef
Mohammed Nadeem Shareef

Posted on

3 2

How to hide password value in inspect using React and Formik

Hello Developers 🀩🀩

Have you ever logged in to Facebook?
Have you ever inspected the Facebook login page?
If not go to Facebook and try inspecting it, you will find the value of the password filed is not showing.

We will replicate that behavior using React and Formik.

Creating Project

npx create-react-app my-app
Enter fullscreen mode Exit fullscreen mode

After project setup, install formik.

npm install formik --save
Enter fullscreen mode Exit fullscreen mode

Basic setup

Setup a basic template for email and password input with submit button.

import { useFormik } from "formik";

function App() {
    return (
        <form>
            <input name="email" type="email" placeholder="email" />
            <input 
                name="password"
                type="password"
                placeholder="password"
            />
            <button type="submit">Submit</button>
        </form>
    );
}

export default App;
Enter fullscreen mode Exit fullscreen mode

Implementing Formik

import { useFormik } from "formik";

function App() {
    const handleSubmit = (values) => {
        console.log(values);
    };

    const formik = useFormik({
        initialValues: {
            email: "",
            password: "",
        },
    });

    return (
        <form
            onSubmit={(e) => {
                e.preventDefault();
                handleSubmit(formik.values);
            }}
        >
            <input
                name="email"
                type="email"
                placeholder="email"
                {...formik.getFieldProps("email")}
            />
            <input
                name="password"
                type="password"
                placeholder="password"
                onChange={formik.handleChange}
                onBlur={formik.handleBlur}
            />
            <button type="submit">Submit</button>
        </form>
    );
}

export default App;
Enter fullscreen mode Exit fullscreen mode

Now check the value in Inspect.
Kaboom πŸ”₯πŸ”₯πŸ”₯
No value in Inspect.

Live Preview

Closing here πŸ‘‹πŸ‘‹πŸ‘‹

Github Code Repo
This is Shareef.
My recent project yourounotes
My Portfolio
Twitter ShareefBhai99
Linkedin
My other Blogs

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay