Skip to content

Instantly share code, notes, and snippets.

@cruelmelody
Last active July 16, 2019 05:00
Show Gist options
  • Save cruelmelody/fc5a1eb6d34118b76d7c273c813a0ec2 to your computer and use it in GitHub Desktop.
Save cruelmelody/fc5a1eb6d34118b76d7c273c813a0ec2 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import BeadCodes from "./data/beadcodes.json";
// import { navigate } from "gatsby"
class IndexPage extends Component {
state = {
barcodeReceiptNo: ""
}
handleInputChange = event => {
const target = event.target
const value = target.value
const name = target.name
this.setState({
[name]: value
});
}
handleSubmit = event => {
event.preventDefault();
alert(`Your barcode number is ${this.state.barcodeReceiptNo}.`);
}
render () {
return (
<>
<form className="submitForm" onSubmit={this.handleSubmit}>
<input
type="text"
name="barcodeReceiptNo"
value={this.state.barcodeReceiptNo}
onChange={this.handleInputChange}
/>
<button type="submit">Submit</button>
</form>
<div>
{BeadCodes.map((beadCode, index) => {
return <h3>{beadCode.code}</h3>
})}
if ({this.state.barcodeReceiptNo} === {beadCode.code}) {
alert("It's a match!")
} else {
alert("Unlucky.")
}
</div>
</>
);
}
}
export default IndexPage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment