Skip to content

Instantly share code, notes, and snippets.

@lucas-moraes
Last active December 17, 2019 16:52
Show Gist options
  • Save lucas-moraes/94058f100f22b4a1c463f42d2aee75c8 to your computer and use it in GitHub Desktop.
Save lucas-moraes/94058f100f22b4a1c463f42d2aee75c8 to your computer and use it in GitHub Desktop.
ReactJS - InputPass with eye magic button
import React, { useState } from "react";
import { InputPassword, ButtonViewPassword } from "../globalStyles";
const InputPass = () => {
const [type, setType] = useState("password");
function toggle(e) {
e.preventDefault();
e.stopPropagation();
setType(type === "text" ? "password" : "text");
}
return (
<div>
<InputPassword type={type} />
<ButtonViewPassword onClick={toggle}>Ver</ButtonViewPassword>
</div>
);
};
export default InputPass;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment