Skip to content

Added first requiredment code i.e formvalidation #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/Home.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
import "./App.css";
import { useState, useEffect } from "react";
import { NavLink } from "react-router-dom";
import { useHistory } from "react-router-dom";

function Home() {
const [text, setText] = useState("");
const [isReady, setIsReady] = useState(false);
const history = useHistory();

const handleChange = (e) => {
setText(e.target.value);
validate();
}

const validate = () => {
const msg = text + '!'
if (msg !== "Ready!") {
setIsReady(false);
} else {
setIsReady(true)
setText("");
}
}

const redirect = () => {
history.push('/pokedex');
}

return (
<div className="App">
<header className="App-header">
<img
hidden={!isReady}
src="https://www.freeiconspng.com/uploads/file-pokeball-png-0.png"
className="App-logo"
alt="logo"
style={{ padding: "10px" }}
/>
<NavLink to="/pokedex">
<img
hidden={!isReady}
src="https://www.freeiconspng.com/uploads/file-pokeball-png-0.png"
className="App-logo"
alt="logo"
style={{ padding: "10px", cursor: "pointer" }}
onClick={redirect}
/>
</NavLink>
<b>
Requirement: Try to show the hidden image and make it clickable that
goes to /pokedex when the input below is "Ready!" remember to hide the
red text away when "Ready!" is in the textbox.
</b>
<p>Are you ready to be a pokemon master?</p>
<input type="text" name="name" />
<span style={{ color: "red" }}>I am not ready yet!</span>
<input type="text" name="name" value={text} onChange={handleChange} />
{!isReady && <span style={{ color: "red" }}>I am not ready yet!</span>}
</header>
</div>
);