Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Last active April 25, 2020 08:10
Show Gist options
  • Save nsisodiya/57c55cd768a4a4f3a9abbbb7b4677661 to your computer and use it in GitHub Desktop.
Save nsisodiya/57c55cd768a4a4f3a9abbbb7b4677661 to your computer and use it in GitHub Desktop.
React + Google Sheet demo - Step 1
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