Skip to content

Instantly share code, notes, and snippets.

@carmandomx
Created February 4, 2021 03:45
Show Gist options
  • Save carmandomx/9bb6cc86d76ba85e7d23685e598687ad to your computer and use it in GitHub Desktop.
Save carmandomx/9bb6cc86d76ba85e7d23685e598687ad to your computer and use it in GitHub Desktop.
Clase: Eventos - Ejercicio Formulario
import "./App.css";
import React, { useState } from "react";
function App() {
const [color, setColor] = useState("#e97878");
const [user, setUser] = useState("");
const [passwd, setPasswd] = useState("");
const [isSubmitted, setIsSubmitted] = useState(false);
const handleLogin = (e) => {
e.preventDefault();
setIsSubmitted(true);
console.log({
user,
passwd,
});
};
return (
<div
className="App"
style={{
backgroundColor: color,
}}
>
{isSubmitted && (
<p>
{" "}
User: {user} y Password: {passwd}{" "}
</p>
)}
<form onSubmit={(e) => handleLogin(e)}>
<input value={user} onChange={(e) => setUser(e.target.value)} />
<input
value={passwd}
onChange={(e) => setPasswd(e.target.value)}
type="password"
/>
<button>Log in</button>
<button type="button">Cancel</button>
</form>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment