Last active
April 25, 2020 08:10
-
-
Save nsisodiya/57c55cd768a4a4f3a9abbbb7b4677661 to your computer and use it in GitHub Desktop.
React + Google Sheet demo - Step 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import "./App.css"; | |
const styles = { | |
InputBox: { | |
padding: 4, | |
}, | |
Error: { | |
color: "red", | |
}, | |
}; | |
function App() { | |
const [name, setName] = useState(""); | |
const [error, setError] = useState(""); | |
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | |
const val = e.target.value; | |
if (val.length >= 5 && val.length <= 20) { | |
setError(""); | |
} else { | |
setError("Name must be between 5 to 20 characters"); | |
} | |
setName(val); | |
}; | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<p> | |
Name:{" "} | |
<input | |
style={styles.InputBox} | |
value={name} | |
onChange={onChange} | |
placeholder="Type your name" | |
/> | |
</p> | |
<p style={styles.Error}>{error}</p> | |
</header> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment